progress
This commit is contained in:
1 parent
2af98b73bb
commit
d2dff1f296
10 files changed
+75
-50
No files matched your search
@@ -19,6 +19,23 @@ namespace bts.analytics
|
||||
return vol;
|
||||
}
|
||||
|
||||
public static double interpolate_vol_array(double[] x, double[] y, double x_val)
|
||||
{
|
||||
if (y == null || x == null || x.Length == 0 || y.Length == 0 || x.Length != y.Length) return double.NaN;
|
||||
int npts = x.Length;
|
||||
if (npts < 3) return Interpolation.interp_linear(x_val, x, y);
|
||||
int klo = 0, khi = npts - 1, k = 0;
|
||||
while (khi - klo > 1)
|
||||
{
|
||||
k = (khi + klo) >> 1;
|
||||
if (x[k] > x_val)
|
||||
khi = k;
|
||||
else
|
||||
klo = k;
|
||||
}
|
||||
return interpolate_vol(x[klo], y[klo], x[khi], y[khi], x_val);
|
||||
}
|
||||
|
||||
public static double interpolate_vol(double t1, double vol1, double t2, double vol2, double t)
|
||||
{
|
||||
if (t1 == t2 || t1 > t)
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Diagnostics;
|
||||
using ExcelDna.Integration;
|
||||
using ExcelDna.IntelliSense;
|
||||
using ExcelDna.Logging;
|
||||
using ExcelDna.Registration;
|
||||
|
||||
namespace bts.excel
|
||||
{
|
||||
@@ -54,6 +55,11 @@ namespace bts.excel
|
||||
Trace.Listeners.Add(new LogDisplayTraceListener("bts"));
|
||||
IntelliSenseServer.Install();
|
||||
ExcelIntegration.RegisterUnhandledExceptionHandler(ex => ex.ToString());
|
||||
|
||||
//https://github.com/Excel-DNA/ExcelDna/issues/255
|
||||
ExcelRegistration.GetExcelFunctions()
|
||||
.ProcessAsyncRegistrations(nativeAsyncIfAvailable: false)
|
||||
.RegisterFunctions();
|
||||
|
||||
load_assemblies();
|
||||
ExcelComAddInHelper.LoadComAddIn(new ContextTeardown(APIDispatch.service_context.Value));
|
||||
|
||||
@@ -14,6 +14,11 @@ namespace bts.excel
|
||||
{
|
||||
public class AnalyticsWrappers
|
||||
{
|
||||
[ExcelFunction]
|
||||
public static double bts_interpolate_vol(double[] t, double[] vol, double x)
|
||||
{
|
||||
return VegaFactor.interpolate_vol_array(t, vol, x);
|
||||
}
|
||||
|
||||
[ExcelFunction]
|
||||
static public double bts_expected_move(double spot, double growth, double vol, double bizt, double calt)
|
||||
|
||||
Binary file not shown.
@@ -11,7 +11,7 @@ using bts.excel;
|
||||
using bts.excel.extensions;
|
||||
using bts.excel.rtd;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.api.orderman
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace bts.api.orderman
|
||||
readonly static Lazy<admin.AdminService> _admin = new Lazy<admin.AdminService>(() => Locator.locate<admin.AdminService>(), true);
|
||||
|
||||
[ExcelFunction(Category = "BTS", Description = "Get All Accessible Accounts")]
|
||||
async public static void spark_get_accounts(string login_token, ExcelAsyncHandle handle)
|
||||
async public static Task<object> spark_get_accounts(string login_token)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -34,11 +34,11 @@ namespace bts.api.orderman
|
||||
accts.Add(acc.Name);
|
||||
}
|
||||
var res = Utilities.make_column_vector(accts.ToArray());
|
||||
handle.SetResult(res);
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
handle.SetException(ex);
|
||||
return ex.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ using ExcelDna.Registration.Utils;
|
||||
using System.Reactive.Linq;
|
||||
using bts.api;
|
||||
using bts.md;
|
||||
using bts.api.orderman;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.excel.rtd
|
||||
{
|
||||
public class MDSubscribe
|
||||
{
|
||||
[ExcelFunction(Category = "BTS", Description = "Log in to BTS Spark")]
|
||||
async public static void spark_login(string login, string password, ExcelAsyncHandle handle)
|
||||
async public static Task<string> spark_login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -23,14 +23,14 @@ namespace bts.excel.rtd
|
||||
if (res.success && Locator.token.HasValue)
|
||||
{
|
||||
_md.set_auth_token(Locator.token);
|
||||
handle.SetResult("Login Successful");
|
||||
return ("Login Successful");
|
||||
}
|
||||
else
|
||||
handle.SetResult("Login Error: Could not log in check user/pass " + res.reason);
|
||||
return ("Login Error: Could not log in check user/pass " + res.reason);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
handle.SetException(ex);
|
||||
return ("Login Exception: " + ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<DnaLibrary Name="spark_excel" RuntimeVersion="v4.0">
|
||||
<ExternalLibrary Path="spark_excel.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" />
|
||||
<ExternalLibrary Path="spark_excel.dll" ExplicitExports="false" ExplicitRegistration="true" LoadFromBytes="true" Pack="true" />
|
||||
|
||||
<Reference Path="spark_analytics.dll" Pack="true" ExplicitExports="true" />
|
||||
<Reference Path="ExcelDna.IntelliSense.dll" Pack="true" />
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.Linq.Dynamic" Version="1.0.7" />
|
||||
|
||||
<PackageReference Include="ExcelDna.AddIn" Version="0.34.6" />
|
||||
<PackageReference Include="ExcelDna.Integration" Version="0.34.6" />
|
||||
<PackageReference Include="ExcelDna.IntelliSense" Version="1.1.0" />
|
||||
<PackageReference Include="ExcelDna.Registration" Version="0.34.7" />
|
||||
<PackageReference Include="ExcelDna.AddIn" Version="1.0.0" />
|
||||
<PackageReference Include="ExcelDna.Integration" Version="1.0.0" />
|
||||
<PackageReference Include="ExcelDna.IntelliSense" Version="1.1.0" />
|
||||
<PackageReference Include="ExcelDna.Registration" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -75,10 +75,10 @@
|
||||
</Target>
|
||||
-->
|
||||
|
||||
<!-- <Import Project="$(NuGetPackageRoot)\ExcelDna.AddIn\0.34.6\tools\ExcelDna.AddIn.targets" Condition="Exists('$(NuGetPackageRoot)\ExcelDna.AddIn\0.34.6\tools\ExcelDna.AddIn.targets')" /> -->
|
||||
<Import Project="$(NuGetPackageRoot)\ExcelDna.AddIn\0.34.6\tools\ExcelDna.AddIn.targets"/>
|
||||
<!-- <Import Project="$(NuGetPackageRoot)\ExcelDna.AddIn\1.0.0\build\ExcelDna.AddIn.targets" Condition="Exists('$(NuGetPackageRoot)\ExcelDna.AddIn\1.0.0\build\ExcelDna.AddIn.targets')" /> -->
|
||||
<!-- <Import Project="$(NuGetPackageRoot)\ExcelDna.AddIn\1.0.0\build\ExcelDna.AddIn.targets"/>
|
||||
<Target Name="EnsureExcelDnaTargetsImported" BeforeTargets="BeforeBuild" Condition="'$(ExcelDnaTargetsImported)' == ''">
|
||||
<Error Condition="!Exists('$(NuGetPackageRoot)\ExcelDna.AddIn\0.34.6\tools\ExcelDna.AddIn.targets') And ('$(RunExcelDnaBuild)' != '' And $(RunExcelDnaBuild))" Text="You are trying to build with ExcelDna, but the NuGet targets file that ExcelDna depends on is not available on this computer. This is probably because the ExcelDna package has not been committed to source control, or NuGet Package Restore is not enabled. Please enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
|
||||
<Error Condition="Exists('$(NuGetPackageRoot)\ExcelDna.AddIn\0.34.6\tools\ExcelDna.AddIn.targets') And ('$(RunExcelDnaBuild)' != '' And $(RunExcelDnaBuild))" Text="ExcelDna cannot be run because NuGet packages were restored prior to the build running, and the targets file was unavailable when the build started. Please build the project again to include these packages in the build. You may also need to make sure that your build server does not delete packages prior to each build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
|
||||
</Target>
|
||||
<Error Condition="!Exists('$(NuGetPackageRoot)\ExcelDna.AddIn\1.0.0\build\ExcelDna.AddIn.targets') And ('$(RunExcelDnaBuild)' != '' And $(RunExcelDnaBuild))" Text="You are trying to build with ExcelDna, but the NuGet targets file that ExcelDna depends on is not available on this computer. This is probably because the ExcelDna package has not been committed to source control, or NuGet Package Restore is not enabled. Please enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
|
||||
<Error Condition="Exists('$(NuGetPackageRoot)\ExcelDna.AddIn\1.0.0\build\ExcelDna.AddIn.targets') And ('$(RunExcelDnaBuild)' != '' And $(RunExcelDnaBuild))" Text="ExcelDna cannot be run because NuGet packages were restored prior to the build running, and the targets file was unavailable when the build started. Please build the project again to include these packages in the build. You may also need to make sure that your build server does not delete packages prior to each build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
|
||||
</Target> -->
|
||||
</Project>
|
||||
@@ -47,32 +47,28 @@ CAPI double liquidity_cost(double qty, double tick_size, double* bookprices, int
|
||||
CAPI double ac_xt(double lambda, double vol, double dt, /*days*/ double T, double s0, double st, double x0,
|
||||
double cost, double adaptivity, int generation, int ngenerations, bool is_buy)
|
||||
{
|
||||
if(generation < ngenerations)
|
||||
{
|
||||
//days
|
||||
if(T < dt)
|
||||
T = dt;
|
||||
double time_factor = 365.0;
|
||||
double sigma = st * vol/ sqrt(time_factor / dt);
|
||||
//double nn = algo().quantity().value() - total_filled().value();
|
||||
double nn = x0;
|
||||
//eta is in ($/share) / (share/period)
|
||||
double eta = dt * cost / nn;
|
||||
double k = sqrt( fabs(lambda) * sigma * sigma / eta );
|
||||
//=IF(B42<=N, U41*SINH(K42*(T-dt*B42))/SINH(K42*(T-dt*B41)),0)
|
||||
double x1 = x0 * sinh(k * (T-dt*generation) ) / sinh(k * T-dt*(generation-1));
|
||||
double alpha = ::log(st/s0) * s0 / time_factor;
|
||||
if(is_buy)
|
||||
alpha = ::log(s0/st) * s0 / time_factor;
|
||||
double x_bar = adaptivity * alpha / (2.0 * lambda * sigma * sigma);
|
||||
double alpha_correct = x_bar * ( 1.0 - ( sinh(k*(T-dt*generation) ) + sinh(k*dt) ) / sinh( k * (T) ) );
|
||||
//=-IF(B42<=N, AA42*(1-(SINH(K42*(T-dt*B42))+SINH(K42*dt))/SINH(K42*(T))),0)
|
||||
double x1_adapt = std::min( std::max( alpha_correct + x1, 0.0), x0);
|
||||
return x1_adapt;
|
||||
}
|
||||
else
|
||||
return x0;
|
||||
if(generation >= ngenerations)
|
||||
return x0;
|
||||
//days
|
||||
if(T < dt)
|
||||
T = dt;
|
||||
double time_factor = 365.0;
|
||||
double sigma = st * vol/ sqrt(time_factor / dt);
|
||||
//double nn = algo().quantity().value() - total_filled().value();
|
||||
double nn = x0;
|
||||
//eta is in ($/share) / (share/period)
|
||||
double eta = dt * cost / nn;
|
||||
double k = sqrt( fabs(lambda) * sigma * sigma / eta );
|
||||
//=IF(B42<=N, U41*SINH(K42*(T-dt*B42))/SINH(K42*(T-dt*B41)),0)
|
||||
double x1 = x0 * sinh(k * (T-dt*generation) ) / sinh(k * T-dt*(generation-1));
|
||||
double alpha = ::log(st/s0) * s0 / time_factor;
|
||||
if(is_buy)
|
||||
alpha = ::log(s0/st) * s0 / time_factor;
|
||||
double x_bar = adaptivity * alpha / (2.0 * lambda * sigma * sigma);
|
||||
double alpha_correct = x_bar * ( 1.0 - ( sinh(k*(T-dt*generation) ) + sinh(k*dt) ) / sinh( k * (T) ) );
|
||||
//=-IF(B42<=N, AA42*(1-(SINH(K42*(T-dt*B42))+SINH(K42*dt))/SINH(K42*(T))),0)
|
||||
double x1_adapt = std::min( std::max( alpha_correct + x1, 0.0), x0);
|
||||
return x1_adapt;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -12,7 +12,7 @@ using bts.api.orderman;
|
||||
using bts.co2;
|
||||
using bts.excel;
|
||||
using bts.excel.rtd;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ExcelDna.Integration;
|
||||
using ExcelDna.Integration.Rtd;
|
||||
@@ -85,7 +85,7 @@ public partial class {{name}}_Excel : IDisposable
|
||||
{{#unless skip_excel_generation}}
|
||||
|
||||
[ExcelFunction(Category = "BTS", Description = "Call BTS Spark {{../lname}} API Method {{lname}} with parameter {{input_type_full}}")]
|
||||
async public static void spark_{{../lname}}_{{lname}}_async (object[,] parameters, ExcelAsyncHandle handle, bool show_headers = false, bool display_vertically = false)
|
||||
async public static Task<object> spark_{{../lname}}_{{lname}}_async (object[,] parameters, bool show_headers = false, bool display_vertically = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -112,7 +112,7 @@ public partial class {{name}}_Excel : IDisposable
|
||||
var members = bts.excel.extensions.ReflectionExtensions
|
||||
.get_fields_or_properties(typeof({{input_type_full}}))
|
||||
.Where(x => !DataParser.excluded_member(x));
|
||||
handle.SetResult(
|
||||
return (
|
||||
"Error in calling method {{lname}}( {{input_type_full}} ), input members are: " +
|
||||
string.Join(",", members.Select(x => x.Name).ToArray())
|
||||
);
|
||||
@@ -123,12 +123,13 @@ public partial class {{name}}_Excel : IDisposable
|
||||
object[,] scattered = new JsonFormatter(res_res).format(show_headers);
|
||||
if(display_vertically)
|
||||
scattered = bts.excel.Utilities.transpose_keep_dimension(scattered);
|
||||
handle.SetResult(scattered);
|
||||
return (scattered);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Trace.TraceError(ex.ToString());
|
||||
handle.SetException(ex);
|
||||
//handle.SetException(ex);
|
||||
return ex.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user