Dynami UI, Project startup

Dynami-UI 6

During last two months Dynami project has grown in silence. I worked mainly under the wood, with new features, minor improvements and a lot of bug fixing. With this pace within few months the first Alpha version will be released.

In summary:

  • Strategy settings can be saved and resumed;
  • PriceChart pane now has BarStick chart, which gives more information on prices than line chart;
  • Positions, Traces and Orders Panes have been improved and rearranged;
  • Financial exposition is measured on margins on open positions;
  • Different volatility estimators have been implemented (ref. measuring_historic_volatility):
    • Close To Close
    • Parkinson
    • Garman-Klass
    • Garman-Klass-Yang-Zhang
    • Rogers-Satchell
    • Yang-Zhang
  • PayoffChart now shows alternatively single legs or cumulative payoff;

DynamiDraft-2016-01-29-1

What are still missing or have to be improved for the Alpha Release:

  • Preferences Pane;
  • Bug Report;
  • Console Pane, to show additional information on internal errors;
  • Errors Pane, has to be strongly improved;
  • DataHandlers:
    • TextFileDataHandler, has still a lot hard coded settings;
    • DataBaseHandler to read data stored in databases;
    • OnlineDataHandler to get data from on-line sources such as Yahoo, Google, etc;

If you have some suggestions or do you want actively contribute to Dynami Project leave a comment.

Dynami Project is an open source project and is provided without warranties in accordance of www.apache.org/licenses/LICENSE-2.0.

Dynami Core, Dynami Runtime, Dynami UI, Project startup

Dynami-Runtime 3

In order to test strategies in options and futures, because I don’t have tons of historical data, I need to simulate prices for all of these instruments. Trying to make them as likely as possible. In this post I’m referring only to European Vanilla Options .

Option is a quite complex financial instrument, because its value is not linear as the stock value is. It is, basically, an insurance contract versus the underlying price movement. As well as, a car insurance premium depends on multiple factors: time, type of car, place where one lives, car-crash history of the driver, also the option price depends on multiple factors*:

  • Underlying spot price
  • Option strike
  • Time to maturity
  • Risk-free interest rate
  • Implied volatility

(*)Black-Scholes model

For simplicity I consider:

  • risk-free interest rate as a constant,
  • implied volatility is equals to the annualized historical volatility of the underlying price.

In real option trading a fundamental role is also played by bid ask spread. In fact the theoretical value is often far from option prices, especially for the OTMs and the ones far in time, while the ITMs have a ceiling in their intrinsic value.

To face this issue I use underlying bid-ask prices to calculate the value of the option’s bid-ask prices. As far as we go far from front-month ATM, the underlying bid-ask spread is multiplied for the distance in strikes and in expiring dates. In this way options’ bid-ask spread become wider and wider moving far from ATM. For example, front-month two strikes OTM is priced using the following underlying spot price:

UnderlyingPrice +/- (BidAskSpread*(1+2)/2

While ATM_Strike+2 @ Front-Month+1 is priced using the following formula:

UnderlyingPrice +/- (BidAskSpread*(1+2+1))/2

2 times more for strike distance and 1 time more for time distance.

Historical volatility is calculated using days left to expiration. With a limit of 10 days for front-month expiration. But volatility skew is currently taken into account.

The following figure, just to show a little progress in Dynami-UI with Payoff chart pane.

DynamiDraft-2015-12-07-1

Glossary:

  • Bid Ask Spread is the difference in price between the highest price that a buyer is willing to pay for an asset and the lowest price for which a seller is willing to sell it.
  • Intrinsic value: The intrinsic value (or “monetary value”) of an option is its value assuming it were exercised immediately.
  • ATM : An option is at the money (ATM) if the strike price is the same as the current spot price of the underlying security.
  • OTM : An out of the money (OTM) option has no intrinsic value.
  • ITM : An in the money (ITM) option has positive intrinsic value as well as time value.

You can find detailed explanation about option moneyness here.

Project startup

Dynami-UI 5

During last two weeks I have been involved in DataHandlerConfig pane re-factoring needed to handle different kinds of configuration parameters, its look and feel can be strongly improved, but now it runs properly. VolatilityChart pane has been completed and Dynami-Runtime can be extended with any kind of historical volatility evaluator. Currently only “Close to close” is available.

Dynami-Runtime project classpath dependencies are now managed by Maven. Dependencies will be progressively moved to Maven, to make them independent from IDE.

But in these days most of the work as has been done under the wood in the TextFileDataHandler class to handle and price option chains for multiple expiration dates.

DynamiDraft-2015-11-22-1

DynamiDraft-2015-11-22-2

Next steps are:

  • Payoff Chart pane
  • Strategy Config pane
  • Improvements in Configuration parameters panes

Dynami project is still far to be completed, but work is going on. If you want to contribute, also with some suggestions, don’t hesitate to leave a comment. Thanks.

Dynami Core, Dynami Runtime, Dynami UI, Project startup

Dynami-UI 4

During last weekend I worked on different fronts in back-end and front-end features. In particular, I deeply revised OptionsChain, Asset.Option classes and added Greeks.Engine and Greeks.ImpliedVolatility interfaces for supporting options greeks calculation, keeping core architecture independent from methods implementation.

Accordingly I have also modified Dynami-Runtime with default implementation for Greeks.Engine, Greeks.ImpliedVolatility. Both based on Black Scholes formula for European Options.

In Dynami-UI:

  • Completed OpenPositions Pane,
  • Completed Traces Pane,
  • Summary Pane is still in progress,
  • while DataHandlerConfig Pane will require more time than expected, because I need to extends some features of an used open-source library.

DynamiDraft-2015-11-07-1

DynamiDraft-2015-11-07-2

Next steps are:

  • VolatilityChart Pane;
  • PayoffChart Pane;
  • Adapt DataHandler for providing simulated option prices;

Disclaimer: BSEurOptionsUtils.java EuropeanBlackScholes.java contain third part code, I got it time ago and sincerely I don’t remember where, so I can’t give the right attribution to the authors. I’m sorry for this.

Dynami UI, Project startup

Dynami-UI 3

The work on Dynami-UI is going on, during this weekend I made some progress:

  • Closed Positions Pane has been completed;
  • Summary Pane is still in progress, but somehow usable;
  • DataHandlerConfig Pane is in progress;
  • Dynami-UI project has been shared on GitHub

Also Dynami-Core and Dynami-Runtime have been updated, new features and some adjustment were necessary to better fit Dynami-UI functionalities and new ones will come. The overall project is a “work in progress”, so if you cloned source code from GitHub remember to check for updates regularly for every project.

Dynami-UI Preferences are still hard coded, one for all: “strategies lib directory”. If you want to run Dynami remember to clone also Dynami-Sample-Strategy project and export it as a jar in its ./resources directory to make your changes effective.

Furthermore, in Dynami-UI ./resources directory is stored a txt file with FTSE MIB index one-minute data, used for simulation.

DynamiDraft-2015-10-31(1)

“Clock frequency” parameter sets the interval, expressed in milliseconds, between one price bar and another and gives the execution speed. If to zero (as shown below) the simulation runs at maximum speed, while UI panes are updated every second (this parameter will be configurable in Preferences).

DynamiDraft-2015-10-31(2)

Next tasks:

  • Completing pending tasks
  • StrategyConfig Pane
  • Open Positions Pane
  • Traces Pane
Dynami UI, Project startup

Dynami-UI 2

Just some updates on project activities. After prototyping stage, I started implementing user interface. As technology I’m using JavaFX for its modular architecture and the clear separation among  models, views and controls. Each panel has its own controller and it can be easily moved without affecting its behaviour.

At the moment, with respect of prototype, I made two little changes:

  • Summary panel has been moved in the bottom right corner.
  • Filled empty space, aside equity line chart, with an undefined chart, suggestions are well accepted.

DynamiDraft-2015-10-24

I’ve just connected UI with Dynami-Runtime and executed Sample-Dynami-Strategy. To achieve alpha release still miss a lot of work, but let’s going on with little steps.

Next features are:

  • Summary panel
  • Closed positions panel
  • DataHandler config panel
Dynami UI, Project startup

Dynami-UI

UI/UX design is one of the most exciting part of software development. I’m not an expert in this field and my approach is based uniquely on my experience and on my feelings. So, if you have some suggestions, please don’t hesitate.

I’ve drawn a mockup, using an open source tool called Pencil – although it seems not actively supported, it is a very good tool, that I strongly recommend.

01.Main window is divided into different sections:

  • menu bar, classic menu, with File [Open, Save, Save as | Preferences | Close] functions, Edit (undefined…), Help (undefined);
  • tool bar, with quick access function to load, configure and execute strategy;
  • quick access for views, such as orders, traces, closed positions, etc;
  • centre pane, with some charts such as Price, Payoff, Equity line, Volatility, etc;
  • portfolio pane, with active positions;
  • strategy summary on the right pane;
  • status bar, for user notifications and error messages.

01.mainwindow

02.Strategy configuration pane to customize strategy parameters for each stage. Designing UI, I realized we need to define some mandatory strategy settings, one for all the main asset symbol. Why? Because if we want to plot asset prices we need to point a particular one.

02.StrategyConfig

03.DataHandler Conguration pane allows to set data handler configuration. Dynami is designed in a modular way, so we can use different data handlers (local data, yahoo data, real-time data, etc) and each handler could have own settings. The goal is keep strategy and data settings separated, to easily switch between test and real-time mode without affecting in any way strategy implementation.

03.datahandlerconfig

04.Orders pane shows orders requests with status.

04.orders

05.Traces pane shows user’s traces with informations directly from strategy.

05.traces

06.Closed positions pane shows closed position with their returns.

06.closed

Stay tuned and fork dynamis’ projects on https://github.com/Dynami

Dynami is an open source project and all source code will be released under http://www.apache.org/licenses/LICENSE-2.0

Glossary:

  • UI – User Interface
  • UX – User eXperience
Dynami Runtime, Java, Project startup

Dynami-Runtime 2

Waiting for Dynami-UI and Dynami-DevTools we can start configuring our development environment using free and open source tools and then start developing and executing our first trading strategy.

Dynami is a Java 8 application, so we need a Java Development Kit (JDK) in order to compile our code. Download the latest Java 8 JDK from Oracle website clicking here.

We also need an IDE for writing Java code. If you are not an experienced Java programmer I suggest you latest “Eclipse IDE for Java Developers”, you can download it clicking here. Also others Java IDEs can be used, but you will need to configure projects’ classpaths manually (Maven porting is in progress, to make classpath settings independent from IDE).

Fork all Dynami projects from GitHub following https://github.com/Dynami. You will find four projects:

  • Dynami-Core contains foundation classes needed to develop trading strategies, root packaged with org.dynami.core.
  • Dynami-Ta is an optional library with a bunch of pre-programmed technical indicators (you can also build your own). Root packaged with org.dynami.ta.
  • Dynami-Runtime contains execution engine and main class to execute the application. Root packaged with org.dynami.runtime.
  • Dynami-Sample-Strategy is a complete and runnable trading strategy.

Just to understand dependencies among projects take a look to following figure. Third part libraries are embedded in “libs” directories. Each library depends from those ones which stand below. Dashed ones are optional.

DynamiRuntimeStack

Now we have all the necessary to start. Dynami currently can be executed only using command line. Yes, I know it is quite tricky and old fashioned, but Dynami’s user interface is still far.

Before starting execution you have to check:

  • all four projects must be compiled without errors (in modern IDEs compilation phase is automatic).
  • Export Dynami-Sample-Strategy as a jar in order to make it executable. If you make some changes you have to re-export it again (in resource directory you will find a compiled one).
  • By default timeframe is set to Daily, you can change it programmatically editing TextFileDataHandler::init() method on Dynamy-Runtime.
    • Set clockFrequence attribute for speed execution. Set to zero for no pauses (max speed execution depends from your PC);
    • Message Broker is forced to sync mode to give deterministic results in test mode.
  • Point org.dynami.runtime.exec.Starter class on Dynami-Runtime check file-paths and execute it as a Java application.

public static void main(String[] args) {
try {
new Starter().execute(new String[]{
// set proper path, but let empty file for the moment
"-file", "../Dynami-Sample-Strategy/resources/myPersonalSettings.dynami",
// set proper path
"-strategy_lib", "../Dynami-Sample-Strategy/resources/dynami.sample.strategy_v1.jar"});
} catch (Exception e) {
e.printStackTrace();
}
}

  • Command strategy execution by command line.

If it’s all ok, a message like this is prompted in console:

Use the following commands to handle strategy execution:
L+Enter        to load
R+Enter        to run/resume
P+Enter        to pause
S+Enter        to stop
E+Enter        to shutdown Dynami
X+Enter        to print strategy status
XX+Enter    to print deep strategy status (with closed positions)

In Dynami-Sample-Strategy we’ve implemented RSI2 trading system developed by Larry Connors. You can find strategy explanation in ChartSchool website clicking here. In this way you can see a real implementation on Dynami.

Dynami is still quite unripe, but it is a working progress. If you have some suggestion leave a comment or write a user story in UserStory page.
Thank you and see you soon.

Glossary:

  • IDE – Integrated Development Environment
  • JDK – Java Development Kit
  • SWT – Standard Widget Toolkit
  • RSI – Relative Strength Index
Dynami Runtime, Project startup

Dynami-Runtime 1

With this article we start describing Dynami-Runtime, the execution engine of Dynami. His mechanism is quite simple and is focused mainly on two components:

  • IExecutionManager, the system entry point, which allows to control strategy execution, managing services and Strategy Executor.
  • IStrategyExecutor the trading strategy handler, which receives financial events and accordingly invokes strategy methods and giving them access to services via IDynami interface.

In summary we can explain the overall functionality with this simple drawing:

DynamiRuntime

Going deeply into IExecutionManager functionalities, we have three blocks of methods:

# Execution control methods:

  • init(Config):boolean;
  • select(String:strategyInstanceFilePath, String:strategyJarPath):boolean;
  • load():boolean;
  • run():boolean;
  • pause():boolean;
  • stop():boolean;

# Check methods:

  • isLoaded():boolean;
  • isStarted():boolean;
  • isRunning():boolean;
  • isSelected():boolean;

# Internal functionalities:

  • addStateListener(StateMachine.ChangeStateListener):void;
  • canMoveTo(State):boolean;
  • setStrategyExecutor(Class<? extends IStrategyExecutor>):boolean;
  • dynami():IDynami;
  • getServiceBus():IServiceBus;
  • msg():IMsg;

Dynami-Runtime is not only the execution engine, but it also contains core services’ implementation (OrderService, PortfolioService, DataService, etc.) and in general what is necessary to load and execute trading strategies.

Communication among components (core services, strategy executor, data provider, and so on) goes through asynchronous messages by event bus. In this way internal components are totally decoupled and expose only user-valuable methods, hiding internal functionalities. Synchronicity can be enabled in test mode to have deterministic results, also if a high execution speed is set up (order of few tens of milliseconds).

Soon will be released a fully functional version, that runs from the command line and FTSEMIB one minute data, in order to develop and run the firsts trading strategies.

Check out Dynami-Runtime source code on GitHub github.com/Dynami/Dynami-Runtime.

Dynami Core, Dynami-TA, Project startup

Dynami-Core 2

In this post we continue the description of Dynami-Core. In particular we will focus on services, which allow strategy developer accessing basic APIs needed for getting historical data, sending order requests, checking open positions, logging information or getting assets.

Dynami services are accessible through IDynami which is passed as parameter in all strategy methods.

Dynami Services are:

  • IDataService retrieves assets  historical data per symbol, time interval and time compression.
  • IOrderService sends order requests and check pending orders.
  • IPortfolioService retrieves open and closed positions.
  • ITraceService allows to log information.
  • IAssetService retrieves set up financial assets and theirs orders books.

Check out source code on Dynami – org.dynami.core.services and let me know if something miss or can be improved.

I’ve added on GitHub Dynami-TA a utility library which wraps TA-LIB and, I hope, makes easier handling technical indicators and price patterns.

Dynami-TA is an optional module, which stays on top of Dynami-Core. So, if you want use it, you need to link both to your trading strategy project.

Stay tuned, in next posts we’ll start with Dynami-Runtime, implementing and executing our first Trading Strategy.

Glossary: