Skip to content

Commit

Permalink
Added Dukascopy example
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedamen committed Jan 10, 2021
1 parent de9980c commit 12b2e7b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ individual data providers)

# Coding log

* 10 Jan 2021
* Added Dukascopy non-equities example
* 08 Jan 2021
* Added extra calendar example
* 05 Jan 2021
Expand Down
3 changes: 3 additions & 0 deletions findatapy/timeseries/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def _get_full_cal(self, cal):
bday = CustomBusinessDay(weekmask='Sat Sun')

holidays_list.append([x for x in pd.date_range('01 Jan 1999', '31 Dec 2025', freq=bday)])
elif cal == 'NOH': #
pass
# holidays_list.append()

else:
label = cal + ".holiday-dates"
Expand Down
59 changes: 59 additions & 0 deletions findatapy_examples/dukascopy_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
__author__ = 'saeedamen' # Saeed Amen

#
# Copyright 2016-2020 Cuemacro
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and limitations under the License.
#


if __name__ == '__main__':
###### below line CRUCIAL when running Windows, otherwise multiprocessing doesn't work! (not necessary on Linux)
from findatapy.util import SwimPool; SwimPool()

# choose run_example = 0 for everything
# run_example = 1 - download EURUSD free tick data from DukasCopy example
# run_example = 2 - download S&P500 free tick data from DukasCopy example

run_example = 2

if run_example == 1 or run_example == 0:

####### DukasCopy examples
# let's download data for 14 Jun 2016 for EUR/USD - the raw data has bid/ask, if we specify close, we calculate
# it as the average

from findatapy.market import Market, MarketDataRequest, MarketDataGenerator

market = Market(market_data_generator=MarketDataGenerator())

# first we can do it by defining all the vendor fields, tickers etc. so we bypass the configuration file
md_request = MarketDataRequest(start_date='14 Jun 2016', finish_date='15 Jun 2016',
fields=['bid'], vendor_fields=['bid'],
freq='tick', data_source='dukascopy',
tickers=['EURUSD'], vendor_tickers=['EURUSD'])

df = market.fetch_market(md_request)
print(df.tail(n=10))

if run_example == 2 or run_example == 0:
####### Dukascopy S&P500 example
from findatapy.market import Market, MarketDataRequest, MarketDataGenerator

market = Market(market_data_generator=MarketDataGenerator())

md_request = MarketDataRequest(start_date='14 Jun 2016', finish_date='15 Jun 2016',
fields=['bid', 'ask'], vendor_fields=['bid', 'ask'],
freq='tick', data_source='dukascopy',
tickers=['S&P500'], vendor_tickers=['USA500IDXUSD'])

# Careful need to divide by 1000.0
df = market.fetch_market(md_request) / 1000.0

print(df)

0 comments on commit 12b2e7b

Please sign in to comment.