Then we can map 2D Texture to 3D using MeshGeometry3D <Viewport3D> <Viewport3D.Camera> <PerspectiveCamera Position="-20,46,0" UpDirection="0,0,1" LookDirection="4,-10,0" NearPlaneDistance="0"/> ...... <GeometryModel3D.Geometry> <MeshGeometry3D Positions="-10,-10,-10 10,-10,-10 10,10,-10 -10,10,-10 -10,-10,10 -10,10,10" TriangleIndices="0 2 3 0 1 2 0 4 3 4 5 3" TextureCoordinates="0,0 0,1 1,1 1,0" />
Monday, May 28, 2012
WPF 3 D Coordinate System with A Camera: Example
Saturday, May 26, 2012
Future Pricing and MR factor model
MATLAB code [hist_date, hist_high, hist_low, hist_open, hist_close, hist_vol] =get_hist_stock_data('SPX','2006'); Data=hist_close; [n,nn] = size(Data); R_dollar=hist_close(2:end)-hist_close(1:end-1); R_pct=R_dollar./hist_close(1:end-1); [b_int,nn,nn,nn,stats] = regress(R_pct,[ones(n-1,1),Data(1:(n-1),1)]); intercept = b_int(1); slope = b_int(2); if (slope > 0) error('Cannot use geometric mean reversion: pct chg=k*(mu-s)+sigma*dW requiring k>0)'); end sigma = sqrt(stats(4)); k = -slope; mu = -intercept/slope; days=20; dT = 1; St=zeros(days,1); St(1)=hist_close(end); for i=1:1:days St(i+1)=St(i)+(k*(mu-St(i))+sigma*normrnd(0,1))*St(i); end % future price dS/S = dLn(F(t))/dt *dt + signma*dW or % Ft-1=Ft*exp(-dS/S+signma*dW) Ft=zeros(days,1); Ft(end)=St(end); for i=days:-1:2 chg =(St(i+1)-St(i))/St(i); Ft(i-1)=Ft(i)*exp(-chg+sigma*normrnd(0,1)); end f1=figure(1); set(f1,'name','%-Return Mean Reversion Factor Model'); p=plot(0:days,St); set(p,'color','red'); hold on; p=plot(1:days,Ft); hold off;

Friday, May 25, 2012
Sunday, April 22, 2012
Visitor Design Pattern
(1) IAccept will Accept any IVisitor, which include all object types in signature. (2) All participating object types implement IAccept with boiler template code visit(this) (3) Visitors are responsible to implement how to visit a type. Benefit: Ensure new visitor must know how to visit all types, and these types does not need to change to allow new visitors.#region IAccept Universal Visitor public interface IVisitor { // List the universe of objects void Visit(Swap sw); void Visit(Option o); void Visit(Bond b); } public interface IAccept { void Accept(IVisitor visitor); } #endregion #region Universal objects Accept any Visitor(this) --boiler template code public class Swap : IAccept { public void Accept(IVisitor visitor) { visitor.Visit(this); } } public class Option : IAccept { public void Accept(IVisitor visitor) { visitor.Visit(this); } } public class Bond : IAccept { public void Accept(IVisitor visitor) { visitor.Visit(this); } } #endregion #region Risk Visitor -- must know how to visitor any objects public class RiskVisitor : IVisitor { public void Visit(Swap sw) { Console.WriteLine("Special works related to Risk of SWAP"); } public void Visit(Option o) { Console.WriteLine("Special works related to Risk of Option"); } public void Visit(Bond b) { Console.WriteLine("Special works related to Risk of Bond"); } } #endregion #region Pricing Visitor -- must know how to visitor any objects public class PricingVisitor : IVisitor { public void Visit(Swap sw) { Console.WriteLine("Special works related to Pricing of SWAP"); } public void Visit(Option o) { Console.WriteLine("Special works related to Pricing of Option"); } public void Visit(Bond b) { Console.WriteLine("Special works related to Pricing of Bond"); } } #endregion // (1) each visitor visit object RiskVisitor rv = new RiskVisitor(); rv.Visit(new Swap()); rv.Visit(new Option()); PricingVisitor pv = new PricingVisitor(); pv.Visit(new Swap()); pv.Visit(new Option()); // (2) each object accept any visitor Swap sw = new Swap(); sw.Accept(new RiskVisitor()); Console.ReadLine();
Saturday, April 21, 2012
WPF Breadcrumb markup
<ListBox Padding="0" DockPanel.Dock="Left" VerticalAlignment="Center" x:Name="lbBreadCrumb" MinWidth="300" Background="Transparent" BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" SelectionChanged="ListBox_SelectionChanged"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Margin="8,0,0,0" Orientation="Horizontal"></StackPanel> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Background" Value="LightGray"/> <Setter Property="BorderBrush" Value="LightGray"/> <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Padding" Value="0"/> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <DockPanel LastChildFill="True" Margin="-8,0,0,0"> <Path x:Name="ArrowTip" DockPanel.Dock="Left" Stroke="LightGray" Fill="LightGray" Data="F1 M 112,144L 104,144L 112,160L 104,176L 112,176" Stretch="Fill" Height="32" Width="12" /> <Path x:Name="Arrow" DockPanel.Dock="Right" Stroke="LightGray" Fill="LightGray" Data="F1 M 168,144L 176,160L 168,176" Stretch="Fill" Height="32" Width="12" /> <Border Name="Border" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Background="{TemplateBinding Background}" BorderBrush="LightGray" Padding="{TemplateBinding Padding}" BorderThickness="0,1,0,1" VerticalAlignment="Center" Margin="-1,0,-1,0" > <ContentPresenter /> </Border> </DockPanel> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter TargetName="Border" Property="Background" Value="Gray"/> <Setter TargetName="Arrow" Property="Fill" Value="Gray"/> <Setter TargetName="ArrowTip" Property="Fill" Value="Gray"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="Red"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ListBox.ItemContainerStyle> <ListBox.ItemTemplate> <DataTemplate> <DataTemplate.Resources> <local:ContentToVisibilityConverter x:Key="c2vConverter" /> </DataTemplate.Resources> <DockPanel VerticalAlignment="Center" Height="30"> <Label DockPanel.Dock="Left" FontSize="8" Content="{Binding Name, FallbackValue=Tagname NA}" VerticalAlignment="Center" Name="lb"/> <Button Width="20" Height="20" Background="#FF1D5BBA" Margin="0" Style="{StaticResource GlassButton}" Visibility="{Binding ElementName=lb, Path=Content., Converter={StaticResource c2vConverter}}"> <Image Width="15" Height="15" Source="images\refresh.png" ToolTip="Refresh Dashboard" MouseLeftButtonDown="RefreshImage_MouseLeftButtonDown" /> </Button> </DockPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
Show WPF Form considering taskbar
// Considering space for Taskbar at the bottom. MONITORINFO monitorInfo = new MONITORINFO(); int MONITOR_DEFAULTTONEAREST = 0x00000001; System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle; System.IntPtr monitor = MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST); GetMonitorInfo(monitor, monitorInfo); RECT rcWorkArea = monitorInfo.rcWork; RECT rcMonitorArea = monitorInfo.rcMonitor; M.Height = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);// SystemParameters.MaximizedPrimaryScreenHeight - 20; M.Width = SystemParameters.MaximizedPrimaryScreenWidth - 15; M.Top = 0; M.Left = 0; #region Win32 API [DllImport("user32")] internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi); ////// /// [DllImport("User32")] internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags); #endregion
Subscribe to:
Posts (Atom)