quantitative-finance

Converting html table to a pandas dataframe

空扰寡人 提交于 2019-12-04 15:48:55
I have been trying to import a html table from a website and to convert it into a pandas DataFrame . This is my code: import pandas as pd table = pd.read_html("http://www.sharesansar.com/c/today-share-price.html") dfs = pd.DataFrame(data = table) print dfs It just displays this: 0 S.No ... But if I do; for df in dfs: print df It outputs the table.. How can I use pd.Dataframe to scrape the table? HTML table on the given url is javascript rendered. pd.read_html() doesn't supports javascript rendered pages. You can try with dryscrape like so: import pandas as pd import dryscrape s = dryscrape

How to use a custom calendar in a custom zipline bundle?

允我心安 提交于 2019-12-03 17:18:36
I have the following code in my viacsv.py file that aims to allow a custom bundle to be ingested: # # Ingest stock csv files to create a zipline data bundle import os import numpy as np import pandas as pd import datetime boDebug=True # Set True to get trace messages from zipline.utils.cli import maybe_show_progress def viacsv(symbols,start=None,end=None): # strict this in memory so that we can reiterate over it. # (Because it could be a generator and they live only once) tuSymbols = tuple(symbols) if boDebug: print "entering viacsv. tuSymbols=",tuSymbols # Define our custom ingest function

Is there any elegant way to define a dataframe with column of dtype array?

穿精又带淫゛_ 提交于 2019-12-03 10:48:26
I want to process stock level-2 data in pandas. Suppose there are four kinds data in each row for simplicity: millis: timestamp, int64 last_price: the last trade price, float64, ask_queue: the volume of ask side, a fixed size (200) array of int32 bid_queue: the volume of bid side, a fixed size (200) array of int32 Which can be easily defined as a structured dtype in numpy: dtype = np.dtype([ ('millis', 'int64'), ('last_price', 'float64'), ('ask_queue', ('int32', 200)), ('bid_queue', ('int32', 200)) ]) And in that way, I can access the ask_queue and bid_queue like: In [17]: data = np.random

How can i see all available data series from quantmod package?

为君一笑 提交于 2019-12-03 06:22:47
问题 How to show which list of all quotes / data series available for example with getSymbols from Yahoo? 回答1: I don't know of a way. The TTR package has a function ( stockSymbols ) to download all the current symbols from the NYSE, AMEX, and NASDAQ. It tries to put them in an acceptable format for Yahoo, but there's no guarantee that the 6,000+ symbols it retrieves have data on Yahoo. I'm not sure what to do for other exchanges... > library(TTR) > x <- stockSymbols() Fetching AMEX symbols...

How can i see all available data series from quantmod package?

我是研究僧i 提交于 2019-12-02 19:45:44
How to show which list of all quotes / data series available for example with getSymbols from Yahoo? I don't know of a way. The TTR package has a function ( stockSymbols ) to download all the current symbols from the NYSE, AMEX, and NASDAQ. It tries to put them in an acceptable format for Yahoo, but there's no guarantee that the 6,000+ symbols it retrieves have data on Yahoo. I'm not sure what to do for other exchanges... > library(TTR) > x <- stockSymbols() Fetching AMEX symbols... Fetching NASDAQ symbols... Fetching NYSE symbols... > str(x) 'data.frame': 6473 obs. of 8 variables: $ Symbol :

Maximum Active Drawdown in python

瘦欲@ 提交于 2019-12-02 18:29:25
I recently asked a question about calculating maximum drawdown where Alexander gave a very succinct and efficient way of calculating it with DataFrame methods in pandas. I wanted to follow up by asking how others are calculating maximum active drawdown ? This calculates Max Drawdown. NOT! Max Active Drawdown This is what I implemented for max drawdown based on Alexander's answer to question linked above: def max_drawdown_absolute(returns): r = returns.add(1).cumprod() dd = r.div(r.cummax()).sub(1) mdd = dd.min() end = dd.argmin() start = r.loc[:end].argmax() return mdd, start, end It takes a

Converting data frame into Time Series using R [duplicate]

浪尽此生 提交于 2019-12-02 04:52:04
This question already has an answer here: How to convert data frame into time series? 5 answers I have a time series data of the format Time Ask Bid Trade Ask_Size Bid_Size Trade_Size 2016-11-01 09:00:12 NA 901 NA NA 100 NA 2016-11-01 09:00:21 NA NA 950 NA NA 5 2016-11-01 09:00:21 NA 950 NA NA 5 NA 2016-11-01 09:00:21 905 NA NA 10 NA NA 2016-11-01 09:00:24 NA 921 NA NA 500 NA 2016-11-01 09:00:28 NA 879 NA NA 2 NA The structure of the dataframe is str(df) 'data.frame': 35797 obs. of 7 variables: $ Time : POSIXct, format: "2016-11-01 09:00:12" "2016-11-01 09:00:21" ... $ Ask : num NA NA NA 905

Writing an expert adviser in [ MQL4 ]

一曲冷凌霜 提交于 2019-12-01 09:18:30
问题 So if I wanted an EA in MQL4 that took the open price and when current price was 10 pips below the open it places a buy order and when it was 10 pips above the open it sold. Only one order at a time and the open changed daily. Q1: How could that run unstopped? Q2: Would that even be profitable? I know this is simple for some people to write but for me it's depressing. 回答1: A1: the simplest part ... The MQL4 Expert Advisor type-of-code's execution can be principally run unstopped, supposing

Convert from R to quantstrat setup for trading strategy backtesting

老子叫甜甜 提交于 2019-11-30 16:57:55
I am trying to backtest a trading strategy with "quantstrat" package. My strategy is composed by 4 indicators, 3 different EMAs and 1 lagged EMA. I want to go long when: EMA1 > EMA2 & EMA1 > EMA3 & EMA1_lag < EMA1 I want to exit and go flat when: EMA1 < EMA3 It's pretty simple but I am not able to write it into quantstrat environment. Here's a data integrity check function used in both examples: # Data integrity check checkBlotterUpdate <- function(port.st,account.st,verbose=TRUE) { ok <- TRUE p <- getPortfolio(port.st) a <- getAccount(account.st) syms <- names(p$symbols) port.tot <- sum

Combining time-series objects and lists: Package “termstrc”

吃可爱长大的小学妹 提交于 2019-11-30 15:33:06
The R package "termstrc", designed for term-structure estimation, is an incredibly useful tool, but it requires data to be set in a particularly awkward format: lists within lists. Question : What is the best way to prepare and shape data, either outside R or inside R, in order to create the repeated sublist format required to run the function "dyncouponbonds"? The "dyncouponbonds" command requires data to be set in a repeated sublist, whereby a list of bonds and time-invariant features of those bonds (let's call this "bondlist"), is appended with some time t features of those bonds (price and