This file contains hidden or 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 pandas as pd | |
| parent_url = 'https://raw.githubusercontent.com/numbers-coffee/blog/master/real_prices/' | |
| currency = pd.read_csv(parent_url + 'currency.csv') | |
| inflation = pd.read_csv(parent_url + 'inflation.csv') | |
| prices = pd.read_csv(parent_url + 'prices.csv') |
This file contains hidden or 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
| from datetime import datetime | |
| date_format = '%Y-%m-%dT%H:%M:%S' | |
| currency['Date'] = currency['DateTime'].apply(lambda x: datetime.strptime(x, date_format)) | |
| inflation['Date'] = inflation['DateTime'].apply(lambda x: datetime.strptime(x, date_format)) | |
| prices['Date'] = prices['DATE'].apply(lambda x: datetime.strptime(x, '%m/%d/%y')) |
This file contains hidden or 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
| from datetime import timedelta | |
| start_date = datetime(1999, 4, 1) | |
| end_date = datetime(2019, 3, 31) | |
| this_date = start_date | |
| date_range = [] | |
| while this_date <= end_date: | |
| date_range.append(this_date) | |
| this_date += timedelta(1) | |
This file contains hidden or 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
| df = pd.merge_asof(continuous_dates, currency[['Date', 'Value']], on='Date', direction='nearest') | |
| df = pd.merge_asof(df, inflation[['Date', 'Value']], on='Date', direction='forward') | |
| df = pd.merge_asof(df, prices[['Date', 'CLOSE']], on='Date', direction='backward') |
This file contains hidden or 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
| df.set_index('Date', inplace=True) | |
| df.rename(columns={ | |
| 'Value_x': 'FX', | |
| 'Value_y': 'Inflation', | |
| 'CLOSE': 'C Market' | |
| }, inplace=True) |
This file contains hidden or 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
| index_date = datetime(2019,3,31) | |
| def index_to_date(date, series): | |
| index_val = series.loc[date] | |
| indexed_series = series / index_val | |
| return indexed_series | |
| df['FX Index'] = index_to_date(index_date, df['FX']) | |
| df.plot(kind='line', y=['FX', 'FX Index'], secondary_y='FX', alpha=.5) |
This file contains hidden or 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 index_annual_rate_to_date(date, series): | |
| daily_rate = (1 + series/100) ** (1/365) | |
| cumulative_rate = daily_rate.sort_index(ascending=False).cumprod() | |
| return index_to_date(date, cumulative_rate) | |
| df['Inflation Index'] = index_annual_rate_to_date(index_date, df['Inflation']) | |
| df.plot(kind='line', y=['Inflation', 'Inflation Index'], secondary_y='Inflation') |
This file contains hidden or 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
| df['C Market (Real)'] = df['C Market'] * df['FX Index'] * df['Inflation Index'] | |
| df.rename(columns={'C Market': 'C Market (Nominal)'}, inplace=True) |
This file contains hidden or 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 matplotlib.pyplot as plt | |
| fig, ax = plt.subplots(figsize=(20,8)) | |
| df.plot(kind='line', y=['C Market (Real)', 'C Market (Nominal)'], ax=ax) | |
| current_price = df.iloc[-1]['C Market (Nominal)'] | |
| ax.axhline(current_price, color='black') |
This file contains hidden or 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 json | |
| import os | |
| import requests | |
| EAS_SCHEMA = "0x76e98cce95f3ba992c2ee25cef25f756495147608a3da3aa2e5ca43109fe77cc" | |
| START_TIME = 0 | |
| RAW_APPLICANT_JSON = "raw_applicant_data.json" | |
| CLEANED_APPLICANT_JSON = "cleaned_applicant_data.json" |