View pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-checkstyle-plugin</artifactId> | |
<version>${checkstyle-maven-plugin.version}</version> | |
<configuration> | |
<dependency> | |
<groupId>com.puppycrawl.tools</groupId> | |
<artifactId>checkstyle</artifactId> | |
<version>${checkstyle.version}</version> | |
</dependency> |
View keepgrabbing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess, urllib, random | |
class NoBlocks(Exception): pass | |
def getblocks(): | |
r = urllib.urlopen("http://{?REDACTED?}/grab").read() | |
if '<html' in r.lower(): raise NoBlocks | |
return r.split() | |
import sys | |
if len(sys.argv) > 1: |
View retirement_portfolio_6.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_expected_portfolio_return(porfolio): | |
return np.sum(portfolio['weight'] * porfolio['returns']) | |
expected_portfolio_return = get_expected_portfolio_return(portfolio) | |
final_value = expected_portfolio_return * PORTFOLIO_VALUE | |
print('Estimated value of Portfolio in {} : £{:,.2f} \nExpected Portfolio Return: {:,.2f}%').format(datetime.now().year + YEARS, final_value, expected_portfolio_return) | |
print('Estimated Income £{:,.2f}').format(final_value * 0.04) |
View retirement_portfolio_5.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_simulation(data): | |
# Get the logarithmic returns of the % change of prices from one trading day to the next. | |
log_returns = np.log(1 + data.pct_change()) | |
# Get the mean of these returns | |
u = log_returns.mean() | |
# Get the variance of these returns | |
var = log_returns.var() | |
# Get the change in the average value of these values | |
drift = u - (0.5 * var) | |
# Get the standard deviation |
View retirement_portfolio_4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_data(stock): | |
data = pd.DataFrame() | |
if stock['type'] == 'index': | |
data = wb.DataReader(stock['ticker'], 'stooq', start=START_DATE)['Close'] | |
return get_simulation(data) | |
data = wb.DataReader(stock['ticker'], 'yahoo', start=START_DATE)['Adj Close'] | |
return get_simulation(data) |
View retirement_portfolio_3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_portfolio(): | |
with open('portfolio.json', 'r') as portfolio_file: | |
portfolio_json = portfolio_file.read() | |
return json.loads(portfolio_json)['portfolio'] | |
portfolio_data = get_portfolio() | |
portfolio = pd.DataFrame(portfolio_data).assign(returns = [get_data(stock) for stock in portfolio_data]) |
View retirement_portfolio_2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
START_DATE = '2007-1-1' # Date from which we want to get the financial year. | |
YEARS = 40 # Years until retirement | |
DAYS_IN_YEAR = 253 # Average number of trading days in the year | |
PORTFOLIO_VALUE = 1000 |
View retirement_portfolio_1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from datetime import datetime | |
import json | |
import numpy as np | |
import pandas as pd | |
from pandas_datareader import data as wb | |
from scipy.stats import norm, gmean |
View portfolio.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"portfolio": [{ | |
"ticker": "^FTM", | |
"name": "FTSE 250", | |
"type": "index", | |
"weight": 0.1 | |
}, | |
{ | |
"ticker": "VEMAX", |