Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters settings using CLI #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ scipy==0.15.1
seaborn==0.5.1
six==1.9.0
urllib3==1.10.4
click
109 changes: 57 additions & 52 deletions scripts/generate_simulated_pair.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import print_function

import click

import calendar
import copy
import datetime
Expand All @@ -23,58 +25,61 @@ def month_weekdays(year_int, month_int):
if d.weekday() < 5 and d.year == year_int
]

@click.command()
@click.option('--seed', default=42, help='Seed (Fix the randomness by default but use a negative value for true randomness)')
@click.option('--pair', default='GBPUSD', help='Currency pair')
@click.option('--s0', default=1.5000, help='S0')
@click.option('--spread', default=0.002, help='spread')
@click.option('--mu_dt', default=1400, help='mu_dt (Milliseconds)')
@click.option('--sigma_dt', default=100, help='sigma_dt (Milliseconds)')
@click.option('--year', default=2014, help='Year')
@click.option('--month', default=1, help='Month')
def main(seed, pair, s0, spread, mu_dt, sigma_dt, year, month):
if seed >= 0:
np.random.seed(seed)

if __name__ == "__main__":
try:
pair = sys.argv[1]
except IndexError:
print("You need to enter a currency pair, e.g. GBPUSD, as a command line parameter.")
else:
np.random.seed(42) # Fix the randomness
ask = copy.deepcopy(s0) + spread / 2.0
bid = copy.deepcopy(s0) - spread / 2.0
days = month_weekdays(year, month) # January 2014 by default
current_time = datetime.datetime(
days[0].year, days[0].month, days[0].day, 0, 0, 0,
)

S0 = 1.5000
spread = 0.002
mu_dt = 1400 # Milliseconds
sigma_dt = 100 # Millseconds
ask = copy.deepcopy(S0) + spread / 2.0
bid = copy.deepcopy(S0) - spread / 2.0
days = month_weekdays(2014, 1) # January 2014
current_time = datetime.datetime(
days[0].year, days[0].month, days[0].day, 0, 0, 0,
)
# Loop over every day in the month and create a CSV file
# for each day, e.g. "GBPUSD_20150101.csv"
for d in days:
current_time = current_time.replace(day=d.day)
print(d.day)
outfile = open(
os.path.join(
settings.CSV_DATA_DIR,
"%s_%s.csv" % (
pair, d.strftime("%Y%m%d")
)
),
"w")
outfile.write("Time,Ask,Bid,AskVolume,BidVolume\n")

# Create the random walk for the bid/ask prices
# with fixed spread between them
while True:
dt = abs(np.random.normal(mu_dt, sigma_dt))
current_time += datetime.timedelta(0, 0, 0, dt)
if current_time.day != d.day:
outfile.close()
break
else:
W = np.random.standard_normal() * dt / 1000.0 / 86400.0
ask += W
bid += W
ask_volume = 1.0 + np.random.uniform(0.0, 2.0)
bid_volume = 1.0 + np.random.uniform(0.0, 2.0)
line = "%s,%s,%s,%s,%s\n" % (
current_time.strftime("%d.%m.%Y %H:%M:%S.%f")[:-3],
"%0.5f" % ask, "%0.5f" % bid,
"%0.2f00" % ask_volume, "%0.2f00" % bid_volume
)
outfile.write(line)

# Loop over every day in the month and create a CSV file
# for each day, e.g. "GBPUSD_20150101.csv"
for d in days:
print(d.day)
current_time = current_time.replace(day=d.day)
outfile = open(
os.path.join(
settings.CSV_DATA_DIR,
"%s_%s.csv" % (
pair, d.strftime("%Y%m%d")
)
),
"w")
outfile.write("Time,Ask,Bid,AskVolume,BidVolume\n")

# Create the random walk for the bid/ask prices
# with fixed spread between them
while True:
dt = abs(np.random.normal(mu_dt, sigma_dt))
current_time += datetime.timedelta(0, 0, 0, dt)
if current_time.day != d.day:
outfile.close()
break
else:
W = np.random.standard_normal() * dt / 1000.0 / 86400.0
ask += W
bid += W
ask_volume = 1.0 + np.random.uniform(0.0, 2.0)
bid_volume = 1.0 + np.random.uniform(0.0, 2.0)
line = "%s,%s,%s,%s,%s\n" % (
current_time.strftime("%d.%m.%Y %H:%M:%S.%f")[:-3],
"%0.5f" % ask, "%0.5f" % bid,
"%0.2f00" % ask_volume, "%0.2f00" % bid_volume
)
outfile.write(line)
if __name__ == "__main__":
main()