示例#1
0
import utils
import pandas as pd

df1 = utils.load_pickle("data/KRW_USD_2019_Q1_Q2.pkl")

df2 = utils.load_pickle("data/KRW_USD_2019_Q3.pkl")

df = utils.concat_two_dfs([df1, df2])

utils.standard_plot(df)

if __name__ == "__main__":
    pass
gold_normals = []

for gold_idx, date in enumerate(normal_target_dates):
    gold = df_gold['Gold'][gold_idx]

    cpi_date = datetime.datetime(date.year, date.month, 1, 0, 0)
    cpi_idx = df_cpi['Date'][df_cpi['Date'] == cpi_date].index.tolist()

    if len(cpi_idx) == 0:
        continue
    else:
        cpi_idx = cpi_idx[0]
    # print(cpi_idx)
    cpi = df_cpi['CPI'][cpi_idx]
    print("cpi: {}, gold: {}".format(cpi, gold))

    normalizer = 100 / cpi
    gold_normal = gold * normalizer
    gold_normals.append(gold_normal)
    gold_normals_date.append(date)

data_cpi_normalized = {'Date': gold_normals_date, 'Gold_Normal': gold_normals}

df_gold_normal = pd.DataFrame(data_cpi_normalized)

utils.standard_plot(df_gold_normal, column_name="Gold_Normal")
utils.pickle_object(df_gold_normal,
                    "../data/gold_daily_normal_cpi_monthly.pkl")
if __name__ == "__main__":
    pass
示例#3
0
import utils
import numpy as np

fname = "volatility_data/gold_daily.pkl"
df = utils.load_pickle(fname)
utils.standard_plot(df, column_name='Volatility')

num_data = df.shape[0]

dates = []
signs = []

count_plus = 0
count_minus = 0
count_zero = 0

spread = 2
bigger_than_spread_dates = []
vols_of_bigger_than_spread_dates = []
how_biggers = []

for idx in range(num_data):
    curr_date = df.loc[idx]["Date"]
    curr_vol = df.loc[idx]["Volatility"]
    if curr_vol > 2:
        bigger_than_spread_dates.append(curr_date)
        vols_of_bigger_than_spread_dates.append(curr_vol)
        print(curr_date, " ", curr_vol, " ", curr_vol - spread)
        how_biggers.append(curr_vol - spread)

    #print(curr_vol)
示例#4
0
import utils

fname = "data/gold_daily.pkl"
df = utils.load_pickle(fname)
utils.standard_plot(df, column_name='Gold')

num_date = df.shape[0]
half_spread = 0.01
# days_holding = 4


def count_profitable_trade_date(days_holding):
    count = 0
    for idx in range(num_date-days_holding):
        curr_date = df.loc[idx]["Date"]
    #    print(curr_date)

        curr_price = df.loc[idx]["Gold"]
        buy_price_w_spread = curr_price * (1 + half_spread)

        sell_date = df.loc[idx+days_holding]["Date"]
        sell_date_price = df.loc[idx+days_holding]["Gold"]
        sell_price_w_spread = sell_date_price * (1 - half_spread)

        arbitrage = sell_price_w_spread - buy_price_w_spread
    #    print(arbitrage)

        if arbitrage >= 0:
            count += 1
            print("Buy Date: {} Arbitrage: {}".format(curr_date, arbitrage))
    print("Total Count: {}".format(count))
示例#5
0
文件: cpi_yearly.py 项目: syyunn/gold
cpis = []

count = 0
for line in lines:
    if count % 3 == 0:
        date = line[0:5].split('\n')[0]
        dates.append(date)
    elif count % 3 == 1:
        cpi = line.split('\n')[0]
        cpis.append(cpi)
    elif count % 3 == 2:
        pass
    count += 1

dates = np.array(dates, dtype='datetime64[Y]')
cpis = np.array(cpis, dtype='float64')

data = {'Date': dates,
        'CPI': cpis}

df = pd.DataFrame(data)

utils.pickle_object(df, "data/{}.pkl".format(filename))

data_path = "data/cpi_yearly.pkl"
df = utils.load_pickle(data_path)
utils.standard_plot(df, column_name='CPI')

if __name__ == "__main__":
    pass
示例#6
0
import utils

fname = "data/gold_daily.pkl"
df = utils.load_pickle(fname)
utils.standard_plot(df, column_name='Gold')

num_data = df.shape[0]

volatiles = []
dates = []

for idx in range(num_data-1):
    curr_day = df.loc[idx]["Date"]
    curr_gold = df.loc[idx]["Gold"]
    tmr_gold = df.loc[idx+1]["Gold"]
    target_volatility = (tmr_gold - curr_gold) / curr_gold
    target_volatility_percentage = target_volatility * 100
    print("idx: {}, vol: {}".format(curr_day, target_volatility_percentage))

    volatiles.append(target_volatility_percentage)
    dates.append(curr_day)

df_volatile = utils.make_as_pandas_df(dates, content_list=volatiles,
                                      content_name="Volatility")

utils.standard_plot(df_volatile, column_name="Volatility")

utils.pickle_object(df_volatile, "gold_daily.pkl")


if __name__ == "__main__":
示例#7
0
dates = []
silvers = []

for line in f.readlines():
    content = line.split(',')
    idx = content[0]
    print(idx)
    if len(idx) == 0:
        continue
    date = content[1]
    silver = content[2].split('\n')[0]
    if len(silver) == 0:
        continue
    print(silver)
    silver = float(silver)

    dates.append(date)
    silvers.append(silver)

df = utils.make_as_pandas_df(dates,
                             content_name='Silver',
                             content_list=silvers)

utils.standard_plot(df, column_name='Silver')

utils.pickle_object(df, "../data/silver_daily.pkl")

if __name__ == "__main__":
    pass