This Java program simulates different investment strategies using historical stock market data. It allows users to test various strategies such as buy and hold, moving average, buying when the stock price is lower than the last purchase, and dollar-cost averaging.
- Simulates investment strategies using historical stock market data based on S&P500 (VOO.csv) monthly close prices with data from 2010-10-01 to 2024-05-01.
- Supports multiple investment strategies: buy and hold, moving average, buy lower than last purchase, and dollar-cost averaging.
- Generates graphical representations of investment results over time.
- Allows users to adjust initial investment, monthly investment amount, and moving average period.
Follow these steps to run the program:
- Clone the repository:
git clone https://github.com/Paul-HenryP/simulate-investment-strategies.git
-
Navigate to the project directory:
-
Open the project in IntelliJ IDEA (or your preferred Java IDE).
-
Ensure that the required dependencies are installed: The project uses Maven for dependency management. IntelliJ IDEA should automatically download the dependencies specified in the
pom.xml
file. If not, you may need to manually trigger a Maven reimport. You can find the pom.xml configuration I used in the end of this file. -
Prepare the historical stock market data: You need to provide historical stock market data in CSV format. Replace the placeholder CSV file
VOO.csv
in the project directory with your own CSV file. Ensure that the CSV file contains the following columns: Date, Open, High, Low, Close, Adj Close, Volume. -
Run the
InvestmentStrategiesChart
class: This is the main class of the program. Running this class will simulate the investment strategies and generate graphical representations of the results.
You can customize the simulation by adjusting the following parameters:
initialInvestment
: The initial amount of money to invest.monthlyInvestment
: The amount of money to invest each month.movingAveragePeriod
: The period (in months) for calculating the moving average in the moving average strategy.
Here's an example of how to use the program:
- Clone the repository and navigate to the project directory.
- Replace the
VOO.csv
file with your own historical stock market data. - Open the project in IntelliJ IDEA.
- Run the
InvestmentStrategiesChart
class. - View the graphical representations of the investment results.
This project is licensed under the MIT License - see the LICENSE file for details.
- This project utilizes the JFreeChart library for generating charts.
Programm loeb hinnad CSV-failist ja katsetab nelja erinevat investeerimisstrateegiat, investeerides algul 1000 ja edaspidi iga kuu 200 eurot (Muudetav) trükkides välja või Maven variandis kuvades iga strateegia tootluse. Kasutatavad strateegiad: Osta ja hoia, liikuv keskmine, sta madalama hinnaga kui eelmine ost, Dollar cost averaging.
-
Laadige alla S&P 500 ajaloolised andmed Yahoo Finance-st CSV-failina: https://finance.yahoo.com/quote/VOO/history/period1=1283990400&period2=1717372800&interval=1mo&filter=history&frequency=1mo&includeAdjustedClose=true või siit repositooriumist ja salvestage see oma projekti kausta, kust programm selle kätte saaks.
-
Kontrollige ja vajadusel muutke programmi csvFile muutuja vastavaks oma CSV-faili teega.
-
Määrake movingAveragePeriod, monthlyInvestment ja initialInvestment väärtused vastavalt vajadusele.
-
Kontrolli pom.xml faili sobivust kui kasutada Maven varianti. Minu pom.xml faili sisu:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>investment-strategies</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.24</version>
</dependency>
</dependencies>
</project>