Skip to content

Commit b43d6fa

Browse files
committed
refactor
1 parent 0c932f8 commit b43d6fa

File tree

9 files changed

+136
-68
lines changed

9 files changed

+136
-68
lines changed

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,47 @@ Using a simple list of buy/sell positions in a csv file as input, this repo aims
2222

2323
## How to use
2424

25-
// TODO
25+
1. Fork this repo, clone to local computer and create a virtual environment
26+
27+
```bash
28+
# could alternatively use virtualenv
29+
conda create --name python-portfolio-tracker --file requirements.txt
30+
31+
```
32+
33+
2. Upload your input data containing the list of buy/sell actions in your portfolio (using the correct format specified in the [Data Input Format](#dif) below). The default location for the input data is: `data/raw/purchase_info.csv`, however, you can upload it anywhere and just reference the location (`input_data_source`) in the load data functions.
34+
35+
<a id='dif'></a>
2636

2737
### Data Input Format
2838

29-
//TODO
39+
The required data input for this analysis is a `csv` file containing rows for each purchase (or disposal) of a stock in your portfolio. An example is given in the `../data/raw/purchase_info.csv` in this repository.
40+
41+
The required columns are:
42+
43+
- `date`: the date of your transaction
44+
- `action`: BUY or SELL
45+
- `company`: the name of the company (this is not sensitive to any further analysis and can be anything of your choosing)
46+
- `yahoo_ticker`: the ticker of the stock on finance.yahoo.com (note this might be different from the actual stock market ticker)
47+
- `currency`: the currency the stock price is denominated in
48+
- `num_shares`: the number of shares involved in the transaction
49+
- `stock_price_usd`: the stock price you bought the stock at on that day
50+
- `trading_costs_usd`: the trading costs incurred
51+
- `total_usd`: the total cost of the transaction
52+
- `total_shares_held`: the total number of shares held after the transaction
53+
54+
Example input format:
55+
56+
| | date | action | company | yahoo_ticker | currency | num_shares | stock_price_usd | trading_costs_usd | total_usd | total_shares_held |
57+
|---:|:-----------|:---------|:------------------|:---------------|:-----------|-------------:|------------------:|--------------------:|------------:|--------------------:|
58+
| 0 | 17/07/2019 | BUY | Nvidia | NVDA | USD | 39 | 166.67 | 4.95 | 6505.08 | 39 |
59+
| 1 | 17/07/2019 | BUY | Intel | INTC | USD | 180 | 49.91 | 4.95 | 8988.75 | 180 |
60+
| 2 | 17/07/2019 | BUY | Applied Materials | AMAT | USD | 268 | 45.9151 | 4.95 | 12310.2 | 268 |
61+
| 3 | 17/07/2019 | BUY | MKS Instruments | MKSI | USD | 120 | 76.7449 | 4.95 | 9214.34 | 120 |
62+
| 4 | 17/07/2019 | BUY | Synopsys | SNPS | USD | 68 | 136.808 | 4.95 | 9307.92 | 68 |
63+
| 5 | 17/07/2019 | BUY | SOXX ETF | SOXX | USD | 75 | 204.261 | 4.95 | 15324.5 | 75 |
64+
| 6 | 26/11/2019 | SELL | Nvidia | NVDA | USD | 5 | 217 | 4.95 | 1089.95 | 34 |
65+
| 7 | 25/03/2020 | BUY | Nvidia | NVDA | USD | 10 | 205.75 | 4.95 | 2062.45 | 44 |
3066

3167
## Current limitations
3268

data/raw/~$input.xlsx

-165 Bytes
Binary file not shown.

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ def nvda_stock_value():
2020
return CalculateStockValue(
2121
ticker=EXAMPLE_TICKER, input_data_source=INPUT_DATA_SOURCE
2222
)
23-
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
date,company,yahoo_ticker,currency,shares_purchased,price_usd,trading_costs_usd,total_usd,total_shares_held
2-
17/07/2019,Nvidia,NVDA,USD,39,166.67,4.95,6505.08,39
3-
17/07/2019,Intel,INTC,USD,180,49.91,4.95,8988.75,180
4-
17/07/2019,Applied Materials,AMAT,USD,268,45.9151,4.95,12310.2,268
5-
17/07/2019,MKS Instruments,MKSI,USD,120,76.7449,4.95,9214.34,120
6-
17/07/2019,Synopsys,SNPS,USD,68,136.8084,4.95,9307.92,68
7-
17/07/2019,SOXX ETF,SOXX,USD,75,204.2607,4.95,15324.5,75
8-
24/07/2019,Tokyo Electron,8035.T,JPY,100,168.4135,126.31,16967.66,100
9-
24/07/2019,BE Semiconductor Industries,BESI.AS,EUR,420,29.9253,100,12668.63,420
1+
date,action,company,yahoo_ticker,currency,num_shares,stock_price_usd,trading_costs_usd,total_usd,total_shares_held
2+
17/07/2019,BUY,Nvidia,NVDA,USD,39,166.67,4.95,6505.08,39
3+
17/07/2019,BUY,Intel,INTC,USD,180,49.91,4.95,8988.75,180
4+
17/07/2019,BUY,Applied Materials,AMAT,USD,268,45.9151,4.95,12310.2,268
5+
17/07/2019,BUY,MKS Instruments,MKSI,USD,120,76.7449,4.95,9214.34,120
6+
17/07/2019,BUY,Synopsys,SNPS,USD,68,136.8084,4.95,9307.92,68
7+
17/07/2019,BUY,SOXX ETF,SOXX,USD,75,204.2607,4.95,15324.5,75
8+
26/11/2019,SELL,Nvidia,NVDA,USD,5,217,4.95,1089.95,34
9+
25/03/2020,BUY,Nvidia,NVDA,USD,10,205.75,4.95,2062.45,44
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
date,company,yahoo_ticker,currency,shares_purchased,purchase_price_usd,trading_costs_usd,total_cost_usd,total_shares_held
2-
17/07/2019,Nvidia,NVDA,USD,39,166.67,4.95,6505.08,39
3-
17/07/2019,Intel,INTC,USD,180,,4.95,8988.75,180
4-
17/07/2019,Applied Materials,AMAT,USD,268,45.9151,4.95,12310.2,268
5-
17/07/2019,,MKSI,USD,120,76.7449,4.95,9214.34,120
6-
17/07/2019,Synopsys,SNPS,USD,68,136.8084,4.95,,68
7-
17/07/2019,SOXX ETF,,USD,75,204.2607,4.95,15324.5,75
8-
24/07/2019,Tokyo Electron,8035.T,JPY,100,168.4135,126.31,16967.66,100
9-
24/07/2019,BE Semiconductor Industries,BESI.AS,EUR,420,29.9253,100,12668.63,420
10-
17/07/2019,Synopsys,SNPS,USD,68,136.8084,4.95,9307.92,68
1+
date,action,company,yahoo_ticker,currency,num_shares,stock_price_usd,trading_costs_usd,total_cost_usd,total_shares_held
2+
17/07/2019,BUY,Nvidia,NVDA,USD,39,166.67,4.95,6505.08,39
3+
17/07/2019,BUY,Intel,INTC,USD,180,,4.95,8988.75,180
4+
17/07/2019,BUY,Applied Materials,AMAT,USD,268,45.9151,4.95,12310.2,268
5+
17/07/2019,BUY,,MKSI,USD,120,76.7449,4.95,9214.34,120
6+
17/07/2019,BUY,Synopsys,SNPS,USD,68,136.8084,4.95,,68
7+
17/07/2019,BUY,SOXX ETF,,USD,75,204.2607,4.95,15324.5,75
8+
24/07/2019,BUY,Tokyo Electron,8035.T,JPY,100,168.4135,126.31,16967.66,100
9+
24/07/2019,BUY,BE Semiconductor Industries,BESI.AS,EUR,420,29.9253,100,12668.63,420
10+
17/07/2019,BUY,Synopsys,SNPS,USD,68,136.8084,4.95,9307.92,68
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
date,company,yahoo_ticker,currency,shares_purchased,purchase_price_usd,trading_costs_usd,total_cost_usd,total_shares_held
2-
17/07/2019,Nvidia,NVDA,USD,39,166.67,4.95,6505.08,39
3-
17/07/2019,Intel,INTC,USD,180,49.91,4.95,8988.75,180
4-
17/07/2019,Applied Materials,AMAT,USD,268,45.9151,4.95,12310.2,268
5-
17/07/2019,MKS Instruments,MKSI,USD,120,76.7449,4.95,9214.34,120
6-
17/07/2019,Synopsys,SNPS,USD,68,136.8084,4.95,9307.92,68
7-
17/07/2019,SOXX ETF,SOXX,USD,75,204.2607,4.95,15324.5,75
8-
24/07/2019,Tokyo Electron,8035.T,JPY,100,168.4135,126.31,16967.66,100
9-
24/07/2019,BE Semiconductor Industries,BESI.AS,EUR,420,29.9253,100,12668.63,420
10-
17/07/2019,Synopsys,SNPS,USD,68,136.8084,4.95,9307.92,68
11-
17/07/2019,Microsoft,MSFT,USD,75,204.2607,4.95,15324.5,75
12-
24/07/2019,Tesla,TSLA,USA,100,168.4135,126.31,16967.66,100
13-
24/07/2019,Diversified Gas and Oil,DGOC.L,GBX,420,29.9253,100,12668.63,420
14-
17/07/2019,BP,BP.L,GBX,68,136.8084,4.95,9307.92,68
15-
17/07/2019,Ford,F,USD,75,204.2607,4.95,15324.5,75
16-
24/07/2019,Facebook,FB,USD,100,168.4135,126.31,16967.66,100
17-
24/07/2019,Snap,SNAP,USD,420,29.9253,100,12668.63,420
18-
17/07/2019,Apple,APPL,USD,68,136.8084,4.95,9307.92,68
19-
17/07/2019,Amazon,AMZN,USD,75,204.2607,4.95,15324.5,75
20-
24/07/2019,ASML,ASML,JPY,100,168.4135,126.31,16967.66,100
21-
24/07/2019,Google,GOOG,USD,420,29.9253,100,12668.63,420
22-
24/07/2019,Mastercard,MA,USD,420,29.9253,100,12668.63,420
1+
date,action,company,yahoo_ticker,currency,num_shares,stock_price_usd,trading_costs_usd,total_cost_usd,total_shares_held
2+
17/07/2019,BUY,Nvidia,NVDA,USD,39,166.67,4.95,6505.08,39
3+
17/07/2019,BUY,Intel,INTC,USD,180,49.91,4.95,8988.75,180
4+
17/07/2019,BUY,Applied Materials,AMAT,USD,268,45.9151,4.95,12310.2,268
5+
17/07/2019,BUY,MKS Instruments,MKSI,USD,120,76.7449,4.95,9214.34,120
6+
17/07/2019,BUY,Synopsys,SNPS,USD,68,136.8084,4.95,9307.92,68
7+
17/07/2019,BUY,SOXX ETF,SOXX,USD,75,204.2607,4.95,15324.5,75
8+
24/07/2019,BUY,Tokyo Electron,8035.T,JPY,100,168.4135,126.31,16967.66,100
9+
24/07/2019,BUY,BE Semiconductor Industries,BESI.AS,EUR,420,29.9253,100,12668.63,420
10+
17/07/2019,BUY,Synopsys,SNPS,USD,68,136.8084,4.95,9307.92,68
11+
17/07/2019,BUY,Microsoft,MSFT,USD,75,204.2607,4.95,15324.5,75
12+
24/07/2019,BUY,Tesla,TSLA,USA,100,168.4135,126.31,16967.66,100
13+
24/07/2019,BUY,Diversified Gas and Oil,DGOC.L,GBX,420,29.9253,100,12668.63,420
14+
17/07/2019,BUY,BP,BP.L,GBX,68,136.8084,4.95,9307.92,68
15+
17/07/2019,BUY,Ford,F,USD,75,204.2607,4.95,15324.5,75
16+
24/07/2019,BUY,Facebook,FB,USD,100,168.4135,126.31,16967.66,100
17+
24/07/2019,BUY,Snap,SNAP,USD,420,29.9253,100,12668.63,420
18+
17/07/2019,BUY,Apple,APPL,USD,68,136.8084,4.95,9307.92,68
19+
17/07/2019,BUY,Amazon,AMZN,USD,75,204.2607,4.95,15324.5,75
20+
24/07/2019,BUY,ASML,ASML,JPY,100,168.4135,126.31,16967.66,100
21+
24/07/2019,BUY,Google,GOOG,USD,420,29.9253,100,12668.63,420
22+
24/07/2019,BUY,Mastercard,MA,USD,420,29.9253,100,12668.63,420

tests/test_data_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from src.data_loader import StockPriceLoader
66

77

8-
TICKERS = ["NVDA", "INTC", "AMAT", "MKSI", "SNPS", "SOXX", "8035.T", "BESI.AS"]
8+
TICKERS = ["NVDA", "INTC", "AMAT", "MKSI", "SNPS", "SOXX"]
99
START_DATE = datetime.datetime(2019, 7, 17)
1010

1111

tests/test_portfolio_value.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88

99
class TestCalculateStockValue:
10+
"""Test CalculateStockValue class"""
11+
1012
def test__get_stock_metadata(self, nvda_stock_value):
1113
"""Test output of stock metadata"""
1214
assert nvda_stock_value.metadata["company"] == "Nvidia"
@@ -19,4 +21,3 @@ def test_calc_portfolio_value():
1921
assert calc_portfolio_value(
2022
input_data_source="./tests/example_inputs/example_purchase_info.csv"
2123
)
22-

0 commit comments

Comments
 (0)