I am having great difficulty with this topic and I could use assistance from some experts.
I have a standard time series, I can have it as an XTS or as a dataframe with numeric inputs. The headers are typical: DATE, OPEN, HIGH, LOW, CLOSE, SMA20, SMA50, CROSSOVER.
SMA20 refers to the 20 periods simple moving average. Crossover refers to where the 20 period SMA is above or below the SMA50. If its positive it is above, if it is negative it is below.
Here is my problem that I am trying to solve. How do I create a separate column to track profits or losses??? I want to create a take profit function at 100 pips and a stop loss function at 100 pips away from the entry point. The entry point will always be the open of the next day, once the crossover happens.
What I am thinking so far is to use the open price, then look at the difference of the high and the low for the day, if difference between the high and the open is greater than 100, the trade gets closed, if it is less, the trades stays open. I have no idea how to begin coding this.
Related
I received readings of multiple multiple filters for a time series x. Those filters are differences of EMAs and EMAs on EMAs. My filters have been calculated as
F1 = EMA(x, period.short) - EMA(x, period.long) and
F2 = ZMA(x, period.short) - ZMA(x, period.long).
ZMA is a delagged EMA which is calculated as EMA(EMA(x, period), period). Unfortunately the original values of the time series x have been lost. Thus, I wonder whether it is possible to somehow reconstruct the original time series. I suppose that an exact reconstruction won't be possible, however to get an glimpse of an idea I'd be already happy to get one possible time series history for the filter values of identical time points.
Therefor I wonder how such a reconstruction could be done in an efficient way and how it could be implemented (if possible in R). Maybe there are already some packages available for such a purpose?!
Thus, I'd be happy if you'd have any advice. Many thanks in advance!
my dataset looks like this (it shows how much time each person takes in going from one place to another, using different cars, taking two stops during the road).
my dataset
I have some NAs on columns "stop time 1" and "stop time 2" and I would like to impute them. Those NAs are not there because people decided to take only 1 or zero stops, but simply because they forgot to record it.
Can you please suggest me how to do this in R? I'm not a data scientist and I'm really new to this. I need to replace those NAs with time stamps (including only hour and minute, e.g. 08:34)
Thanks!!
P.s.: will the algorithm be able to impute on those two columns by taking into account that, since they represent stops between departure and arrival, they have to be comprehended between departure and arrival?
I'm quite new to time series and I am wondering what is the best way to identify the starting date of a period with low values of a variable. So in this example I would in a first step want to i) identify whether there is such a period of let's say at least 5 values that are similarly low and ii) what the starting date of this period is.
So in this example (https://i.stack.imgur.com/IxLQg.png) for the first 3 individuals (c15793, c15798 and c3556) I want to figure out that there is such a period and that the starting date is on the 20th of May for c15798 and on the 22nd of May for the other two. But c5157 should be identified as not having such a period.
I have no clue on how I could identify such a period and I was hoping someone would have an idea and point me to a method or a point where I could start. Everything I can think of would require some sort of threshold (e.g. the difference between consecutive measurements) which I don't know how to choose. So if anyone has a more elegant idea or a good idea on how to set a threshold, I would be more than happy to learn about it.
Thanks so much in advance!
enter image description here
I am trying to extract data from one data set (contains water quality data -- chlorophyll, dissolved oxygen, temp, etc), using information from another data set that contains tidal information (low tide times).
Background: It has recently come to my attention that due to hydrodynamics it will be best to only look at WQ data points measured at low tide, when I had previously just taken the daily average.
Is there a way I can extract specific WQ data based on if it aligns with date/time of the tidal data??? Caveats -- the times might not match up exactly, WQ data was measured every 15 minutes so I need the closest point(s) to the low tide time.
It is difficult to give the exact code without knowing the frequency of your tidal data. However, you can take a look at the following links, using which you could match the timestamps on both your datasets by rounding them off to the nearest hour/half hour/quarter hour (as the case may be):
rounding times to the nearest hour in R
Rounding time to nearest quarter hour
Hope this helps.
I have a "succeeded" metric that is just the timestamp. I want to see the time between successive successes (this is how long the data is stale for). I have
derivative(Success)
but I also want to know how long between the last success time and the current time. since derivative transforms xs[n] to xs[n+1] - xs[n], the "last" delta doesn't exist. How can I do this? Something like:
derivative(append(Success, now()))
I don't see any graphite functions for appending series, and I don't see any user-defined graphite functions.
The general problem is to be alerted when the data is stale, via graphite monitoring. There may be a better solution than the one I'm thinking about.
identity is a function whose value at any given time is the timestamp of that time.
keepLastValue is a function that takes a series and replicates data points forward over gaps in the data.
So then diffSeries(identity("now"), keepLastValue(Success)) will be a "sawtooth" series that climbs steadily while Success isn't updated, and jumps down to zero (or close to it — there might be some time skew) every time Success has a data point. If you use graphite monitoring to get the current value of that expression and compare it to some threshold, it will probably do what you want.