SharedmongoTests.ipynbOpen in CoCalc
Arctic tests
# import arctic library
from arctic import Arctic
# import pandas
import pandas as pd
# import quandl library
import quandl
# import plots
import matplotlib as plt

# Start mongod on localhost
#!mongod --dbpath /home/user/mongo_data
# Pull some data from qandl
aapl = quandl.get("WIKI/AAPL", authtoken="rkeazqH5yf2RspNwACei")
# have a look at it
aapl.head()
Open High Low Close Volume Ex-Dividend Split Ratio Adj. Open Adj. High Adj. Low Adj. Close Adj. Volume
Date
1980-12-12 28.75 28.87 28.75 28.75 2093900.0 0.0 1.0 0.422706 0.424470 0.422706 0.422706 117258400.0
1980-12-15 27.38 27.38 27.25 27.25 785200.0 0.0 1.0 0.402563 0.402563 0.400652 0.400652 43971200.0
1980-12-16 25.37 25.37 25.25 25.25 472000.0 0.0 1.0 0.373010 0.373010 0.371246 0.371246 26432000.0
1980-12-17 25.87 26.00 25.87 25.87 385900.0 0.0 1.0 0.380362 0.382273 0.380362 0.380362 21610400.0
1980-12-18 26.63 26.75 26.63 26.63 327900.0 0.0 1.0 0.391536 0.393300 0.391536 0.391536 18362400.0
# Connect to Local MONGODB
store = Arctic('localhost')

# Create the library - defaults to VersionStore
store.initialize_library('NASDAQ')

# Access the library
library = store['NASDAQ']

# Store the data in the library
library.write('AAPL', aapl, metadata={'source': 'Quandl'})

# Reading the data
item = library.read('AAPL')
aapl_out = item.data
metadata = item.metadata
Library created, but couldn't enable sharding: no such command: 'enablesharding', bad cmd: '{ enablesharding: "arctic", lsid: { id: UUID("a5f15b0f-a9e6-4f4f-86b0-e28568cff758") }, $readPreference: { mode: "secondaryPreferred" }, $db: "admin" }'. This is OK if you're not 'admin'
# Look at data just pulled from mongo!
aapl_out

WARNING: Some output was deleted.
aapl_out['Close'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7f97fee97320>
# Make some new data
testdata = pd.DataFrame({
        'a': [1,2,3,4,5],
        'b': ['a', 'a', 'b', 'a', 'c']
    })

# Make a new library
store.initialize_library('test')

# Access the library
testlib = store['test']

# Store the data in the library
library.write('TESTDATA', testdata, metadata={'source': 'made it up'})

# Reading the data
item = testlib.read('TESTDATA')
testdata_out = item.data
metadata = item.metadata

Library created, but couldn't enable sharding: no such command: 'enablesharding', bad cmd: '{ enablesharding: "arctic", lsid: { id: UUID("a5f15b0f-a9e6-4f4f-86b0-e28568cff758") }, $readPreference: { mode: "secondaryPreferred" }, $db: "admin" }'. This is OK if you're not 'admin'
# Data back in a dataframe
testdata_out
a b
index
0 1 a
1 2 a
2 3 b
3 4 a
4 5 c
# Import some data from csv
futData = pd.read_csv('/home/user/data.csv')
futData

WARNING: Some output was deleted.

# Store the data in existing library 
library = store['NASDAQ']
library.write('futData', futData, metadata={'source': 'NYMEX'})

# Reading the data
item = library.read('futData')
testdata_out = item.data
metadata = item.metadata
Library created, but couldn't enable sharding: no such command: 'enablesharding', bad cmd: '{ enablesharding: "arctic", lsid: { id: UUID("a5f15b0f-a9e6-4f4f-86b0-e28568cff758") }, $readPreference: { mode: "secondaryPreferred" }, $db: "admin" }'. This is OK if you're not 'admin'

# List symbols in library
library.list_symbols()
['AAPL', 'TESTDATA', 'futData']
item = library.read('futData')
item.data
WARNING: Some output was deleted.