Tag Archives: problems

MotiveWave SDK Java no 3rd party coding problems so far

Here they are as there are few 3rd party examples

BIG UPDATE BELOW which means I got this partially working!!

I tested to add a Redis NOSQL (3rd party) using simple Jedis Jar. This was done fairly easily with another Mac OS based proprietary platform like Dukascopy JForex. I could see the Redis update when running the strategy or study within MotiveWave. This builds fine. but there does not seem debugging log capabilities for a strategy but there is for studies. Also, when making changes in the Java in Eclipse, the MotiveWave platform does not seem to pick up the latest changes  in a dynamically changed class.  The only way for this to be picked up is by reseting the platform.

My opinion but it is looking good but …

I think there needs to a be lot more samples from MotiveWave instead of just 3 simple studies and 1 strategy. I could only find one other 3rd party providing further examples. Unfortunately, I am not  in the business of spinning my wheels to figure this out as compared to other brokers/platform who provide flawless coding experiences. I think I need to see a demo or better examples.

Until then, I am may just use MotiveWave for charting or connecting with IQFeed only. I can do that with the entry level MotionWave edition. This platform is very exciting indeed but I need to get to see improvements in the above area before I get serious with it from a coding point for view.

BIG UPDATE on getting Java coding! (Nov 29)

See the video to see what is working including text writing and CSV reading files

Here is working Java code as hinted in the video

package study_examples;

import com.motivewave.platform.sdk.common.Coordinate;

import com.motivewave.platform.sdk.common.DataContext;

import com.motivewave.platform.sdk.common.DataSeries;

import com.motivewave.platform.sdk.common.Defaults;

import com.motivewave.platform.sdk.common.Enums;

import com.motivewave.platform.sdk.common.Inputs;

import com.motivewave.platform.sdk.common.MarkerInfo;

import com.motivewave.platform.sdk.common.desc.InputDescriptor;

import com.motivewave.platform.sdk.common.desc.IntegerDescriptor;

import com.motivewave.platform.sdk.common.desc.MAMethodDescriptor;

import com.motivewave.platform.sdk.common.desc.MarkerDescriptor;

import com.motivewave.platform.sdk.common.desc.PathDescriptor;

import com.motivewave.platform.sdk.common.desc.SettingGroup;

import com.motivewave.platform.sdk.common.desc.SettingTab;

import com.motivewave.platform.sdk.common.desc.SettingsDescriptor;

import com.motivewave.platform.sdk.common.desc.ValueDescriptor;

import com.motivewave.platform.sdk.draw.Marker;

import com.motivewave.platform.sdk.study.RuntimeDescriptor;

import com.motivewave.platform.sdk.study.Study;

import com.motivewave.platform.sdk.study.StudyHeader;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import redis.clients.jedis.Jedis;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

/** Moving Average Cross. This study consists of two moving averages: 

    Fast MA (shorter period), Slow MA. Signals are generated when the 

    Fast MA moves above or below the Slow MA. Markers are also displayed 

    where these crosses occur. */

@StudyHeader(

  namespace=”com.mycompany”, 

  id=”MACROSS”, 

  name=”Sample Moving Average Cross”,

  label=”MA Cross”,

  desc=”Displays a signal arrow when two moving averages (fast and slow) cross.”,

  menu=”Examples”,

  overlay=true,

  signals=true)

public class SampleMACross extends Study

{

  enum Values { FAST_MA, SLOW_MA };

  enum Signals { CROSS_ABOVE, CROSS_BELOW };

  @Override

  public void initialize(Defaults defaults)

  {

try {

File file = new File(“/Users/quantlabsnet/atestfile1.txt”);

FileWriter fileWriter = new FileWriter(file);

fileWriter.write(“This is “);

fileWriter.write(“a test”);

fileWriter.flush();

fileWriter.close();

} catch (IOException e) {

this.debug(e.toString());

e.printStackTrace();

}

//https://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/

String csvFile = “/Users/quantlabsnet/country.csv”;

    BufferedReader br = null;

    String line = “”;

    String cvsSplitBy = “,”;

    try {

        br = new BufferedReader(new FileReader(csvFile));

        while ((line = br.readLine()) != null) {

            // use comma as separator

            String[] country = line.split(cvsSplitBy);

            this.debug(“Country [code= ” + country[4] + ” , name=” + country[5] + “]”);

        }

    } catch (FileNotFoundException e) {

        e.printStackTrace();

        this.debug(e.toString());

    } catch (IOException e) {

        e.printStackTrace();

        this.debug(e.toString());

    } finally {

        if (br != null) {

            try {

                br.close();

            } catch (IOException e) {

                e.printStackTrace();

                this.debug(e.toString());

            }

        }

    }

// Jedis jedis = new Jedis(“localhost”); 

//    this.debug(“Connection to server sucessfully”); 

//    //check whether server is running or not 

//    this.debug(“Server is running: “+jedis.ping()); 

 

this.debug(“hello debug from SampleMACross()”);

 

    // User Settings

    SettingsDescriptor sd=new SettingsDescriptor();

    setSettingsDescriptor(sd);

    SettingTab tab=new SettingTab(“General”);

    sd.addTab(tab);

    // Fast MA (shorter period)

    SettingGroup ma1=new SettingGroup(“Fast MA”);

    tab.addGroup(ma1);

    ma1.addRow(new InputDescriptor(Inputs.INPUT, “Fast Input”, Enums.BarInput.CLOSE));

    ma1.addRow(new MAMethodDescriptor(Inputs.METHOD, “Fast Method”, Enums.MAMethod.EMA));

    ma1.addRow(new IntegerDescriptor(Inputs.PERIOD, “Fast Period”, 10, 1, 9999, 1));

    // Slow MA (shorter period)

    SettingGroup ma2=new SettingGroup(“Slow MA”);

    tab.addGroup(ma2);

    ma2.addRow(new InputDescriptor(Inputs.INPUT2, “Slow Input”, Enums.BarInput.CLOSE));

    ma2.addRow(new MAMethodDescriptor(Inputs.METHOD2, “Slow Method”, Enums.MAMethod.EMA));

    ma2.addRow(new IntegerDescriptor(Inputs.PERIOD2, “Slow Period”, 20, 1, 9999, 1));

    tab=new SettingTab(“Display”);

    sd.addTab(tab);

    SettingGroup lines=new SettingGroup(“Lines”);

    tab.addGroup(lines);

    lines.addRow(new PathDescriptor(Inputs.PATH, “Fast MA”, defaults.getGreenLine(), 1.0f, null, true, false, false));

    lines.addRow(new PathDescriptor(Inputs.PATH2, “Slow MA”, defaults.getBlueLine(), 1.0f, null, true, false, false));

    SettingGroup markers=new SettingGroup(“Markers”);

    tab.addGroup(markers);

    markers.addRow(new MarkerDescriptor(Inputs.UP_MARKER, “Up Marker”, Enums.MarkerType.TRIANGLE, Enums.Size.SMALL, defaults.getGreen(), defaults.getLineColor(), true, true));

    markers.addRow(new MarkerDescriptor(Inputs.DOWN_MARKER, “Down Marker”, Enums.MarkerType.TRIANGLE, Enums.Size.SMALL, defaults.getRed(), defaults.getLineColor(), true, true));

    // Runtime Settings

    RuntimeDescriptor desc=new RuntimeDescriptor();

    setRuntimeDescriptor(desc);

    desc.setLabelSettings(Inputs.INPUT, Inputs.METHOD, Inputs.PERIOD, Inputs.INPUT2, Inputs.METHOD2, Inputs.PERIOD2);

    desc.exportValue(new ValueDescriptor(Values.FAST_MA, “Fast MA”, new String[] { Inputs.INPUT, Inputs.METHOD, Inputs.PERIOD }));

    desc.exportValue(new ValueDescriptor(Values.SLOW_MA, “Slow MA”, new String[] { Inputs.INPUT2, Inputs.METHOD2, Inputs.PERIOD2 }));

    desc.exportValue(new ValueDescriptor(Signals.CROSS_ABOVE, Enums.ValueType.BOOLEAN, “Cross Above”, null));

    desc.exportValue(new ValueDescriptor(Signals.CROSS_BELOW, Enums.ValueType.BOOLEAN, “Cross Below”, null));

    desc.declarePath(Values.FAST_MA, Inputs.PATH);

    desc.declarePath(Values.SLOW_MA, Inputs.PATH2);

    // Signals

    desc.declareSignal(Signals.CROSS_ABOVE, “Fast MA Cross Above”);

    desc.declareSignal(Signals.CROSS_BELOW, “Fast MA Cross Below”);

    desc.setRangeKeys(Values.FAST_MA, Values.SLOW_MA);

  }

  @Override

  protected void calculate(int index, DataContext ctx)

  {

    int fastPeriod=getSettings().getInteger(Inputs.PERIOD);

    int slowPeriod=getSettings().getInteger(Inputs.PERIOD2);

    if (index < Math.max(fastPeriod, slowPeriod)) return; // not enough data

    DataSeries series=ctx.getDataSeries();

    // Calculate and store the fast and slow MAs

    Double fastMA=series.ma(getSettings().getMAMethod(Inputs.METHOD), index, fastPeriod, getSettings().getInput(Inputs.INPUT));

    Double slowMA=series.ma(getSettings().getMAMethod(Inputs.METHOD2), index, slowPeriod, getSettings().getInput(Inputs.INPUT2));

    if (fastMA == null || slowMA == null) return;

    series.setDouble(index, Values.FAST_MA, fastMA);

    series.setDouble(index, Values.SLOW_MA, slowMA);

    if (!series.isBarComplete(index)) return;

    // Check to see if a cross occurred and raise signal.

    Coordinate c=new Coordinate(series.getStartTime(index), slowMA);

    if (crossedAbove(series, index, Values.FAST_MA, Values.SLOW_MA)) {

      MarkerInfo marker=getSettings().getMarker(Inputs.UP_MARKER);

      if (marker.isEnabled()) addFigure(new Marker(c, Enums.Position.BOTTOM, marker));

      ctx.signal(index, Signals.CROSS_ABOVE, “Fast MA Crossed Above!”, series.getClose(index));

    }

    else if (crossedBelow(series, index, Values.FAST_MA, Values.SLOW_MA)) {

      MarkerInfo marker=getSettings().getMarker(Inputs.DOWN_MARKER);

      if (marker.isEnabled()) addFigure(new Marker(c, Enums.Position.TOP, marker));

      ctx.signal(index, Signals.CROSS_BELOW, “Fast MA Crossed Below!”, series.getClose(index));

    }

    series.setComplete(index);

  }

}

 

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Apply physics math problems with Python

Apply physics math problems with Python

A good intro tutorial for those wanting to learn the language to apply physics and math to their solutions

http://www.codeproject.com/Articles/1087025/Using-Python-to-Solve-Computational-Physics-Proble

Join my FREE newsletter to learn how to apply Python to your automated trading

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Blame backtesting for these trading problems

Blame backtesting for these trading problems

Don’t get overly dependent on this process for your trading ideas. But this does not help

As securities watchdogs crack down on complex investments that promise mom-and-pop investors access to strategies of trading pros, Wall Street is finding a way to sell the same products in places those regulators don’t reach.

To read the entire article, go to http://bloom.bg/1P8u6f7

Join my FREE newsletter to learn more about how I use backtesting for my algo trading

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Meetup Webinar Tues Jun 10 at 6 PM EST: Use of R core scripting to eliminate ‘NA’ (“and other common recycled value problems”?)

Meetup Webinar Tues Jun 10 at 6 PM EST: Use of R core scripting to eliminate ‘NA’ (“and other common recycled value problems”?)

Body of presentation:
I Use of rm() inside of source code

This following portion is still under construction as I haven’t gotten as much feedback as would be helpful from core R team yet…

II Manually coding a ‘divisor procedure’ to help eliminate recycling issues when machine level precision is approached

Tuesday June 10 at 6PM EST

 

Join our FREE newsletter to learn more about these type of webinars 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Problems of HFT players who front load for (payment for order flow) payment of flow from other brokers

Problems of HFT players who front load for (payment for order flow) payment of flow from other brokers

like TD Ameritrade

They see the orders in the queue before orders are executed. WTF? Why is this allowed?
Being on the exchange allows HFT servers to have access to fast direct market feeds vs aggregated feeds called
Join my FREE newsletter to find out the other questionable problems

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Rigged markets because of HFT the problems and potential solutions

Rigged markets because of HFT the problems and potential solutions
From Jeff Solomon on Bloomberg TV
Sorry about the cummy typing as typed in a rush:
HFT and speed trumps price discovery. Inequity who gets the market feed.
More efficient markets today and faster. Small cap market require wider big spread and slower market.
Feeds are faster so run get stock before regular execution for normal.
Need wider increment for market depth for fundamental with real price discovery (buy and sell opp). Used to have it.
SEC needs pilot for wider increment in 5 cent increments. Need discrement for better price discovery.. Queue. Too many increments. Killing small cap companies but volume moved to larger cap for liquidity.
Small cap is 2% of volume for companies less than $750M.
Less market balance today so small caps getting killed.
IEX could be the crusaders from Mike Lewis. They are trusted. He said they are interesting service.
Join my FREE newsletter to learn about potential solutions and impact

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Problems logging into Interactive Brokers TWS?

Here is what I posted in my new knowledgebase

I still have trouble with my username and password.  This has been a recurring problem.  Can you take a look, please?  Maybe send me a link where I login and everything works, please?

As a temporary solution,  Check out:

Custom Trading Course

Module 2 Interacting with Interactive Brokers Trader Workstation TWS for automated trading – See more at: http://quantlabs.net/academy/elite-member-courses/#sthash.5UccFrkS.dpuf

Unit 2 Interactive Brokers TWS demo and setup

If that is not useful, I would suggest go to Interactive Brokers support. I wish I could provide more

Interested in going Elite like all real quant do ? Join here

Or join my FREE newsletter to learn more on trading stuff like this

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Which R package for Estimating sample size for regression problems

Which R package for Estimating sample size for regression problems

Hello. I am currently taking an online short course that attempts to estimate the sample size. Currently I am trying to estimate the sample size for simple linear regression and multiple regression problems. The course focuses on other software packages to estimate the sample size (Lenth’s applet, Power and Precicion, nQuery, etc.). However, I would like to use R since I am trying to become familer with it and I am still somewhat of a newbie. My question is if anyone knows of any R packages that I could use to estimate the sample size for regression problems?

For example, in one problem in the course notes the sample size should be calculated for a simple linear regression with an R2 = 0.5, significance level = 0.05, and power is 0.8. However, I cannot find an acceptable R package/program where I can estimate the sample size and test statistic (so I can determine if the Wetz criterion is met)?

Also another problem using a multiple regression problem with 3 regressors and trying to estimate the sample size if the objective is to show an R2 = 0.7 with a power of 0.9 (ignoring Wetz criterion) .

Thanks for any help so I can try to answer these questions with R.

==

 

• You have power level and error, and need to figure out sample sizes…

Doing some quick research, I found something that may interest you: http://www.ats.ucla.edu/stat/R/dae/t_test_power3.htm

One particular section notes:

In R, it is fairly straightforward to perform a power analysis for the paired sample t-test using R’s pwr.t.test function.

For the calculation of Example 1, we can set the power at different levels and calculate the sample size for each level. For example, we can set the power to be at the .80 level at first, and then reset it to be at the .85 level, and so on. First, we specify the two means, the mean for the null hypothesis and the mean for the alternative hypothesis. Then we specify the standard deviation for the difference in the means. The default significance level (alpha level) is set at .05, so we will not specify it for the initial runs. Last, we tell R that we are performing a paired-sample t-test.

library(pwr)

pwr.t.test(d=(0-5)/5,power=0.8,sig.level=0.05,type=”paired”,alternative=”two.sided”)

Paired t test power calculation

n = 9.93785
d = 1
sig.level = 0.05
power = 0.8
alternative = two.sided

NOTE: n is number of *pairs*

Granted, you are looking for regression rather than a paired t-test. But I believe this should be very close to what you have in mind. All you’d need to do at that point is switch t-test for the regression you’re trying to perform.

 

=

There is a whole package of power functions that you can use to find power or sample size. One of those functions (pwr.f2.test) will do the power for all general models, hence, for example, for regression.
see:
http://cran.r-project.org/web/packages/pwr/pwr.pdf

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Are we getting lazy trying to solve quant analytical problems?

Are we getting lazy trying to solve quant analytical problems?

I used to use maths, write simulations and use statistical programs. now what I do is throw almost an variable I think of into a data mining software and let it work it out. Then I just work Do you think that is true for most people now?
==Given the sense of urgency to solving business problems, companies may not be patient to allow someone to “manually” select variables and build/validate models. I would not say we we are lazy. The tool could be entirely wrong becasue of the way the data was created or it does not generate results that make sense to the business instincts.
However, you still need all the math and stats talent to decipher the results. Sometimes, the tool, in my case SAS Enterprise Miner, may recommend a certain set of variables, but the business may disagree. As you know there is a lot of art and science in this work, so the tools help automate certain tedious tasks like varaible selection and model development/comparisons, but past experience/education is required to go with the course of action that makes the most sense to the business.
I laugh when people think anyone can throw data into a tool and spit out a model. Like any analytics tool, it’s only as good as the data its fed and there is no “magic” button.
==I agree with everything except that it does not save time, it takes more time. In my case it is formulize. A typical example might be I spend ages collecting data. then set it up for a four hour run but discover that I have made a basic error, so the next day I fix it up and run it again. Then I fix it up again, then run it over night. Discover some extra stuff. Then run it again and so on. It only stops when I finally give up and say it is good enough. Being a perfectionist that is a long time.
==I agree – this work is very iterative and unstructured. My boss gave me some good advice: “Don’t destroy the good for the best.” At some point, we have to realize what we have developed is better than what we started with and deliver it. Otherwise, we will never finish.== have a Professor that often says “Computing power is cheap” I personally think that with the advancements in computers and statistical packages, part of the job of the statistician is to find that balance between brain power and computing power that solves the problem most efficiently.

 

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!