-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis_netpositionratio_vs_price.py
executable file
·68 lines (55 loc) · 2.27 KB
/
analysis_netpositionratio_vs_price.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import logging
import os.path # To manage paths
import sys # To find out the script name (in argv[0])
import argparse
import backtrader as bt
import dontbuffer
import backtrader.analyzers as btanalyzers
import pandas as pd
import numpy as np
import time
import scipy.stats as stats
import pickle
import logging
#import copy
import configparser
from pprint import pprint, pformat
from sklearn.preprocessing import MinMaxScaler
from sklearn.decomposition import PCA
from os import listdir
from os.path import isfile, join
import pickle
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
import scipy.stats as stats
import math
from statsmodels.tsa.stattools import coint
from backfill_data import batch_backfill, separate_bid_ask_midpoint
def parse_args():
parser = argparse.ArgumentParser(
description='Bid/Ask Line Hierarchy',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
return parser.parse_args()
if __name__ == '__main__':
# logging.basicConfig(level=logging.CRITICAL, format='[%(levelname)s] %(asctime)s %(message)s', datefmt="%H:%M:%S")
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(asctime)s %(message)s', datefmt="%H:%M:%S")
pairs = ["AUD_JPY", "AUD_USD", "EUR_AUD", "EUR_CHF", "EUR_GBP", "EUR_JPY", "EUR_USD", "GBP_CHF", "GBP_JPY", "GBP_USD", "NZD_USD", "USD_CAD", "USD_CHF", "USD_JPY", "XAG_USD", "XAU_USD"]
for p in pairs:
df = pd.read_csv("cron/open_positions/{}/2017-07-07_11-58.csv".format(p))
df["timestamp"] = pd.to_datetime(df['timestamp'],unit='s')
df["pct_short"] = 100.0 - df["pct_long"]
df["net"] = df["pct_long"] - df["pct_short"]
df["net_change"] = df["net"].pct_change()
df["price_change"] = df["price"].pct_change()
df.set_index("timestamp", inplace=True)
df_norm = (df - df.mean()) / (df.max() - df.min())
print("*" * 50)
print(p)
# print(df[["net_change", "price_change"]].corr(method="spearman"))
df_norm[["net_change", "price_change"]].plot()
print(df_norm[["net_change", "price_change"]].corr(method="spearman"))
# print(df.head())
# print(df.head())
# plt.show()