All Projects → uelel → simulatePortfolio

uelel / simulatePortfolio

Licence: MIT License
class for simulation of stock investing portfolios based on historical data

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to simulatePortfolio

Beibo
🤖 Predict the stock market with AI 用AI预测股票市场
Stars: ✭ 46 (+155.56%)
Mutual labels:  finance, stocks, investment
investbook
Оценка эффективности инвестиций с учетом комиссий, налогов (удержанных и ожидающихся), дивидендов и купонов.
Stars: ✭ 83 (+361.11%)
Mutual labels:  finance, stocks, investment
FinanceKit
FinanceKit is a Framework for iOS and Mac to build apps working with financial data, like money, currencies, stocks, portfolio, transactions and other concepts.
Stars: ✭ 15 (-16.67%)
Mutual labels:  finance, stocks
finam-export
Python client library to download historical data from finam.ru
Stars: ✭ 84 (+366.67%)
Mutual labels:  stocks, investment
ProjectReward
A software to shortlist and find the best options spread available for a given stock and help it visualise using payoff graphs.
Stars: ✭ 57 (+216.67%)
Mutual labels:  finance, stocks
AlphaVantageAPI
An Opinionated AlphaVantage API Wrapper in Python 3.9. Compatible with Pandas TA (pip install pandas_ta). Get your FREE API Key at https://www.alphavantage.co/support/
Stars: ✭ 77 (+327.78%)
Mutual labels:  finance, stocks
DCF
Basic Discounted Cash Flow library written in Python. Automatically fetches relevant financial documents for chosen company and calculates DCF based on specified parameters.
Stars: ✭ 198 (+1000%)
Mutual labels:  finance, investment
optlib
A library for financial options pricing written in Python.
Stars: ✭ 166 (+822.22%)
Mutual labels:  finance, stocks
Finance-Robinhood
Trade stocks and ETFs with free brokerage Robinhood and Perl
Stars: ✭ 42 (+133.33%)
Mutual labels:  finance, stocks
AutoTrader
A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
Stars: ✭ 227 (+1161.11%)
Mutual labels:  finance, stocks
TradeRepublicApi
Unofficial trade republic API
Stars: ✭ 134 (+644.44%)
Mutual labels:  finance, stocks
IEX CPP API
Unofficial C++ Lib for the IEXtrading API
Stars: ✭ 34 (+88.89%)
Mutual labels:  finance, stocks
Stocksera
Web application that provides alternative data to retail investors
Stars: ✭ 426 (+2266.67%)
Mutual labels:  finance, stocks
py-investment
Extensible Algo-Trading Python Package.
Stars: ✭ 19 (+5.56%)
Mutual labels:  finance, investment
pyEX
Python interface to IEX and IEX cloud APIs
Stars: ✭ 407 (+2161.11%)
Mutual labels:  finance, stocks
fundamentos
Download Bovespa Stock Market fundamentals with Python.
Stars: ✭ 80 (+344.44%)
Mutual labels:  finance, stocks
cira
Cira algorithmic trading made easy. A Façade library for simpler interaction with alpaca-trade-API from Alpaca Markets.
Stars: ✭ 21 (+16.67%)
Mutual labels:  finance, stocks
Mida
The open-source and cross-platform trading framework
Stars: ✭ 263 (+1361.11%)
Mutual labels:  finance, stocks
degiro-trading-tracker
Simplified tracking of your investments
Stars: ✭ 16 (-11.11%)
Mutual labels:  stocks, investment
stockscore
A python project to fetch stock financials/statistics and perform preliminary screens to aid in the stock selection process
Stars: ✭ 54 (+200%)
Mutual labels:  finance, stocks

simulatePortfolio

simulatePortfolio is a Python class that upon instantiation simulates performance of portfolio with stock instruments.

The main goal of this project is to provide basic metrics of long(er)-term investments based on the historical data and investment strategy.


Features

  • the simulator was developed for tracking long(er)-term investments with the time horizon of at least several months

  • the simulator implements initial and monthly contributions and two kinds of instrument purchases:

    • initial purchase: of all instruments during the start date
    • regular purchases: of defined number of instruments at defined monthly intervals.
  • the simulator acknowledges commission scheme typical for brokerage services:

    • absolute fee: absolute fee during purchase of one instrument
    • relative fee: fraction of purchased volume during purchase of one instrument
    • connection fee: absolute fee per calendar year
  • it is necessary to define instrument weights in portfolio.
    The instrument weights are aimed to be preserved during simulation by solving of this SOE regularly:




Usage

import datetime
from sp import simulatePortfolio

inst1 = {'name':'iShares S&P500', 'data':{datetime.date(2019, 1, 1): 259.05, datetime.date(2019, 2, 1): 276.162, datetime.date(2019, 3, 1): 282.065, datetime.date(2019, 4, 1): 291.348, datetime.date(2019, 5, 1): 287.017, datetime.date(2019, 6, 1): 286.0, datetime.date(2019, 7, 1): 299.4, datetime.date(2019, 8, 1): 294.882, datetime.date(2019, 9, 1): 296.533, datetime.date(2019, 10, 1): 299.253, datetime.date(2019, 11, 1): 311.615, datetime.date(2019, 12, 1): 318.435, datetime.date(2020, 1, 1): 326.11, datetime.date(2020, 2, 1): 325.68}}
inst2 = {'name':'Xetra Gold', 'data': {datetime.date(2019, 1, 1): 36.24, datetime.date(2019, 2, 1): 36.99, datetime.date(2019, 3, 1): 36.92, datetime.date(2019, 4, 1): 36.99, datetime.date(2019, 5, 1): 36.49, datetime.date(2019, 6, 1): 37.8, datetime.date(2019, 7, 1): 39.44, datetime.date(2019, 8, 1): 41.02, datetime.date(2019, 9, 1): 44.66, datetime.date(2019, 10, 1): 43.42, datetime.date(2019, 11, 1): 43.55, datetime.date(2019, 12, 1): 42.53, datetime.date(2020, 1, 1):44.03, datetime.date(2020, 2, 1):45.85}}

simulatePortfolio([[inst1, 0.8, 2.0, 0.00038],
                   [inst2, 0.2, 2.0, 0.00038]],
                  currency = 'EUR',
                  connectionFeePerYear = 2.5,
                  startDate = datetime.date(2019, 1, 1),
                  endDate = datetime.date(2020, 1, 1),
                  initCont = 2500,
                  monthCont = 200,
                  monthsPerTrade = 2,
                  instrumentsPerTrade = 2)

1. Historical data

inst1 = {'name':'iShares S&P500', 'data':{datetime.date(2019, 1, 1): 259.05, datetime.date(2019, 2, 1): 276.162, datetime.date(2019, 3, 1): 282.065, datetime.date(2019, 4, 1): 291.348, datetime.date(2019, 5, 1): 287.017, datetime.date(2019, 6, 1): 286.0, datetime.date(2019, 7, 1): 299.4, datetime.date(2019, 8, 1): 294.882, datetime.date(2019, 9, 1): 296.533, datetime.date(2019, 10, 1): 299.253, datetime.date(2019, 11, 1): 311.615, datetime.date(2019, 12, 1): 318.435, datetime.date(2020, 1, 1): 326.11, datetime.date(2020, 2, 1): 325.68}}
inst2 = {'name':'Xetra Gold', 'data': {datetime.date(2019, 1, 1): 36.24, datetime.date(2019, 2, 1): 36.99, datetime.date(2019, 3, 1): 36.92, datetime.date(2019, 4, 1): 36.99, datetime.date(2019, 5, 1): 36.49, datetime.date(2019, 6, 1): 37.8, datetime.date(2019, 7, 1): 39.44, datetime.date(2019, 8, 1): 41.02, datetime.date(2019, 9, 1): 44.66, datetime.date(2019, 10, 1): 43.42, datetime.date(2019, 11, 1): 43.55, datetime.date(2019, 12, 1): 42.53, datetime.date(2020, 1, 1):44.03, datetime.date(2020, 2, 1):45.85}}

Historical data are nested dict with name and data keys.
The actual data points consist of datetime.date objects coupled with instrument prices per share.

  • It is possible to load daily or monthly prices
  • Monthly prices should be coupled to the same day in month for all instruments (e.g. all prices are defined on the 1st day of month)

2. Portfolio

[[inst1, 0.8, 2.0, 0.00038],
 [inst2, 0.2, 2.0, 0.00038]]

Portfolio is list of some instruments.
Each instrument takes the form [historical data, weight, absolute fee, relative fee]

3. Currency

currency = 'EUR'

Currency symbol for informative purposes.

4. Start, end date

startDate = datetime.date(2019, 1, 1),
endDate = datetime.date(2020, 1, 1)

datetime.date objects defining simulation timespan.

5. Connection fee

connectionFeePerYear = 2.5

Absolute fee per calendar year.

6. Initial and monhtly contributions

initCont = 2500,
monthCont = 200

Contributed amount for initial and regular investments, respectively.

7. Months per trade

monthsPerTrade = 2

How many months should be between regular investments.

8. Instruments per trade

instrumentsPerTrade = 1

How many instruments should be traded during each regular investment.


Example

from the previous code:


Known issues

  • plots may be distrorted when plotted from terminal.
    Use jupyter notebook or different matplotlib backend.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].